我无法理解这行代码。请帮助
frames=[PhotoImage(file="chatgif.gif",format="gif -index %i" %(i)) for i in range(20)]
%i
是字符串格式语法。这里它创建20个字符串"gif -index <NUMBER>"
,其中数字从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
EDIT(感谢@blckknht(:str.format()
:的替代方案
frames=[PhotoImage(file="chatgif.gif",format="gif -index {}".format(i)) for i in range(20)]