list = [yes, no, seven]
print ("What do you want to pull from the list?")
answer = input()
print (list[answer])
我该如何处理这种情况?我知道这个例子不起作用,但是如何让它起作用?从变量列表中调用东西
编辑:我宁愿它是数字I输入,0是,1表示没有发生; 2七,如果这是可能的
list = [yes, no, seven]
print ("What do you want to pull from the list?")
answer = input()
print (list[answer])
我该如何处理这种情况?我知道这个例子不起作用,但是如何让它起作用?从变量列表中调用东西
编辑:我宁愿它是数字I输入,0是,1表示没有发生; 2七,如果这是可能的
你正在寻找一个dict
,而不是一个list
。
my_dictionary = {'yes':1, 'no':4, 'seven':9}
answer = input("What do you want to pull from the dictionary? ")
print(my_dictionary[answer])
list_ = [yes, no, seven]
print ("What do you want to pull from the list?")
answer = input()
print (list_[list_.index(answer)])
[如何删除列表中的项目(如果它存在? (Python的)](http://stackoverflow.com/questions/4915920/how-to-delete-an-item-in-a-list-if-it-exists-python) –