啊哈,代码有错误,只有数字类型的字符串能运行,我修改了一下a = []
string=1
while string:
string = input()
if string:
a.append(string)
for item in range(len(a)):
exec(f'string{item} = a[item]')
print(eval(f'string{item}'))
比如你想生成一些变量,但是具体生成几个还没有想好
测试生成5个变量
abcd
语文
1234
aa123
数学98A
abcd
语文
1234
aa123
数学98A
>>> string0
'abcd'
>>> string1
'语文'
>>> string2
'1234'
>>> string3
'aa123'
>>> string4
'数学98A'
>>> string5
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
string5
NameError: name 'string5' is not defined
|