format - String formatting in Python version earlier than 2.6 -
When I run the following code in Python 2.5.2:
For (1, 11): Print '{0: 2d} {1: 3d} {2: 4d}'. Format (x, x * x, x * x * x) I get:
traceback (most recent call final): File " & Lt; pyshell # 9 "gt; Line 2, & lt; Module & gt; Print '{0: 2d} {1: 3d} {2: 4d}'. Format (x, x * x, x * x * x) Attribute Enter: 'str' object has no attribute 'format'<I do not understand the problem.
to
dir ('hello')is not aformatattribute.How can I solve it?
str.formatmethod was Python 2.6 and later.
Comments
Post a Comment