【发布时间】:2017-09-21 03:21:56
【问题描述】:
使用我的代码,我试图让用户输入来选择数组中的一个值,但是当存在固定值(例如 2)时它可以工作,但是当提到 input() 时它就不起作用了。
highstreet = ['tp' ,'io','fffffff','mmmmmm','ice']
x = input
highstreet[x]
print(highstreet[x])
>> highstreet[x]
>>TypeError: list indices must be integers or slices, not
builtin_function_or_method
谢谢
【问题讨论】:
-
x = input将函数input分配给变量x。如果你想调用输入函数,并将结果赋值给x,你的意思是x = input()