我需要使用访问字符串raw_input
.
list1 = ["one","Two","three"]
list2 = ["1","2","3"]
while True:
ip = raw_input("enter list: ")
for i in ip:
print i
break
当“list1”作为输入给出时,它采用字符串而不是列表。
我需要访问上面定义的列表。
我需要一种访问列表并打印列表的方法。
使用字典:
lists = {
"list1": ["one","Two","three"],
"list2": ["1","2","3"],
}
while True:
choice = raw_input("enter the list name: ")
try:
for item in lists[choice]:
print item
except KeyError:
print "I never heard of any list named '{}'! Try again.".format(choice)
else:
break
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)