Python版本早于2.6的字符串格式 [英] String formatting in Python version earlier than 2.6

查看:110
本文介绍了Python版本早于2.6的字符串格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Python 2.5.2中运行下面的代码:

  for x in range(1,11):
print'{0:2d} {1:3d} {2:4d}'。


$ b




$ b

  Traceback(最近的最后一次调用):
在< module>中,第2行的文件< pyshell#9>
print'{0:2d} {1:3d} {2:4d}'格式(x,x * x,x * x * x)
AttributeError:'str'对象没有属性'format'

我不明白这个问题。



dir('hello')没有格式属性。



如何解决这个问题?

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆