【发布时间】:2021-08-25 05:09:06
【问题描述】:
我是 python 新手,我已经在我的代码中声明了一些变量,但它们几乎相似,我想知道是否可以使用 for 循环等来简化它,以免有10行声明?
Left_10 = PhotoImage(file = 'image_10.jpg')
Left_9 = PhotoImage(file = 'image_9.jpg')
Left_8 = PhotoImage(file = 'image_8.jpg')
Left_7 = PhotoImage(file = 'image_7.jpg')
Left_6 = PhotoImage(file = 'image_6.jpg')
Left_5 = PhotoImage(file = 'image_5.jpg')
Left_4 = PhotoImage(file = 'image_4.jpg')
Left_3 = PhotoImage(file = 'image_3.jpg')
Left_2 = PhotoImage(file = 'image_2.jpg')
Left_1 = PhotoImage(file = 'image_1.jpg')
感谢您的帮助
【问题讨论】:
-
不要那样做。使用正确的数据结构。检查stupidpythonideas.blogspot.com/2013/05/…
-
这能回答你的问题吗? How do I create variable variables?
标签: python for-loop variables declaration