我正在寻找一种用户输入变量的方法,它可以从列表中的特定位置调用列表信息
list = ["0","2","4","8"]
a = input("Enter the list entry you want to retrieve: ")
print (list[a])
如果输入1,则将打印2,如果输入2,则将打印4
答案 0 :(得分:1)
将“ a”转换为整数。
list = ["0","2","4","8"]
a = input("Enter the list entry you want to retrieve: ")
print (list[int(a)])