当我在 Python 2.5.2 中运行以下代码时:
for x in range(1, 11):
print '{0:2d} {1:3d} {2:4d}'.format(x, x*x, x*x*x)
我得到:
Traceback (most recent call last):
File "<pyshell#9>", line 2, in <module>
print '{0:2d} {1:3d} {2:4d}'.format(x, x*x, x*x*x)
AttributeError: 'str' object has no attribute 'format'
我不明白这个问题。
从dir('hello')
那里没有format
属性。
我该如何解决这个问题?