String formatting in Python version earlier than 2.6

前端 未结 5 755

When I run the following code in Python 2.5.2:

for x in range(1, 11):
    print \'{0:2d} {1:3d} {2:4d}\'.format(x, x*x, x*x*x)

I get:

5条回答
  •  一生所求
    2020-12-16 10:00

    The str.format method was introduced in Python 3.0, and backported to Python 2.6 and later.

提交回复
热议问题