String formatting in Python version earlier than 2.6

前端 未结 5 752

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:13

    Which Python version do you use?

    Edit For Python 2.5, use "x = %s" % (x) (for printing strings)

    If you want to print other types, see here.

提交回复
热议问题