我想int
加入一个string
.这就是我现在正在做的事情:
num = 40
plot.savefig('hanning40.pdf') #problem line
Run Code Online (Sandbox Code Playgroud)
我必须运行几个不同数字的程序,而不是两个40.所以我想做一个循环但插入这样的变量不起作用:
plot.savefig('hanning', num, '.pdf')
Run Code Online (Sandbox Code Playgroud)
如何将变量插入Python字符串?
"(%d goals, $%d)" % (self.goals, self.penalties)
原始问题:Python 3中的字符串格式
Python3格式字符串语法参考:https://docs.python.org/3/library/string.html#format-string-syntax