当我在Python 2.5.2中运行以下代码时:
for x in range(1, 11):
print '{0:2d} {1:3d} {2:4d}'.format(x, x*x, x*x*x)
Run Code Online (Sandbox Code Playgroud)
我明白了:
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'
Run Code Online (Sandbox Code Playgroud)
我不明白这个问题.
从dir('hello')没有format属性.
我怎么解决这个问题?