我有一本字典,里面有名字和他们与卢克·天行者的关系:
names = {'Darth Vader' : 'Father', 'Leia' : 'Sister'}
我的代码要求输入名称,当您输入名称时,它会从字典中吐出值。
print('Enter a name:')
name = input()
print(names[name])
当我运行我的代码并输入“Darth Vader”时,它会返回“Father”。但是当我第二次这样做时,它给了我一个语法错误。
Darth Vader
File "<stdin>", line 1
Darth Vader
^
SyntaxError: invalid syntax