python如何创建用户输入的数量的list?
python比如用raw_input()用户输入了3,那么就创建3个list,名称分别为A,B,C。如果输入了4,就创建4个list,名称分别为ABCD...
python 比如用raw_input()用户输入了3,那么就创建3个list,名称分别为A,B,C。如果输入了4,就创建4个list,名称分别为A B C D
展开
展开全部
希望能提供给你一个思路,另外使用exec也可以
>>> import string
>>> string.ascii_uppercase
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
>>> num = raw_input("Enter a number:")
Enter a number:5
>>> for i in range(int(num)):
... locals()[string.ascii_uppercase[i]] = []
...
>>> A
[]
>>> B
[]
>>> C
[]
>>> D
[]
>>> E
[]
>>> F
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'F' is not defined
>>> import string
>>> string.ascii_uppercase
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
>>> num = raw_input("Enter a number:")
Enter a number:5
>>> for i in range(int(num)):
... locals()[string.ascii_uppercase[i]] = []
...
>>> A
[]
>>> B
[]
>>> C
[]
>>> D
[]
>>> E
[]
>>> F
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'F' is not defined
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询