“ValueError: zero length field name in format” error in Python 3.0,3.1,3.2

后端 未结 3 597
情歌与酒
情歌与酒 2020-11-29 05:18

I\'m trying learn Python (3 to be more specific) and I\'m getting this error:

ValueError: zero length field name in format

I googled it and

3条回答
  •  醉梦人生
    2020-11-29 05:41

    Python 2.6 and 3.0 require the field numbers. In Python 2.7 and later and 3.1 and later, they can be omitted.

    Changed in version 2.7: The positional argument specifiers can be omitted, so '{} {}' is equivalent to '{0} {1}'.

    python2.6.4>>> print '|{0:^12}|{1:^12}|'.format(3,4)
    |     3      |     4     |
    

提交回复
热议问题