Python 3.x 代码**frames=[PhotoImage(file=";chatgf.gif";,format=";gif-索引%i";%(i))中的%i在范围(20)中的含义是什么**

Python 3.x 代码**frames=[PhotoImage(file=";chatgf.gif";,format=";gif-索引%i";%(i))中的%i在范围(20)中的含义是什么**,python-3.x,Python 3.x,我无法理解这行代码。请帮忙 frames=[PhotoImage(file="chatgif.gif",format="gif -index %i" %(i)) for i in range(20)] %i是。在这里,它创建了20个字符串“gif-index”,其中数字从0到19: 例如: for i in range(10): print( "gif -index %i" % (i) ) 印刷品: gif -index 0

我无法理解这行代码。请帮忙

frames=[PhotoImage(file="chatgif.gif",format="gif -index %i" %(i)) for i in range(20)]
%i
是。在这里,它创建了20个字符串
“gif-index”
,其中数字从0到19:

例如:

for i in range(10):
    print( "gif -index %i" % (i) )
印刷品:

gif -index 0
gif -index 1
gif -index 2
gif -index 3
gif -index 4
gif -index 5
gif -index 6
gif -index 7
gif -index 8
gif -index 9

编辑(感谢@blckknght):使用
str.format()

%i
是。在这里,它创建了20个字符串
“gif-index”
,其中数字从0到19:

例如:

for i in range(10):
    print( "gif -index %i" % (i) )
印刷品:

gif -index 0
gif -index 1
gif -index 2
gif -index 3
gif -index 4
gif -index 5
gif -index 6
gif -index 7
gif -index 8
gif -index 9

编辑(感谢@blckknght):使用
str.format()


您可能希望使用
str.format
或f-strings将代码翻译成更现代的示例。您可能希望使用
str.format
或f-strings将代码翻译成更现代的示例。