您可以使用来更改字符串中的值
%。文档可以在这里找到。
例如:
num = 2print "1 + 1 = %i" % num # i represents an integer
这将输出:
1 +1 = 2
您也可以使用浮点数执行此操作,并且可以选择要打印的小数位数:
num = 2.000print "1.000 + 1.000 = %1.3f" % num # f represents a float
给出:
1.000 + 1.000 = 2.000
在示例中使用它来更新
t图形标题:
plt.figure(1)plt.ylabel('y')plt.xlabel('x')for t in xrange(50,61): plt.title('f model: T=%i' %t) for i in xrange(4,10): plt.plot(1.0/i,i**2,'ro') plt.legend plt.show()


