动态式批量生成变量的方法

﹥>﹥吖頭↗ 提交于 2019-11-28 12:20:00

使用函数locals()

>>> for i in range(5):
...     locals()['X%s' % i] = ''
...
>>> print(X0,X1,X2,X3,X4)

>>> print(X5)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'X5' is not defined

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!