【发布时间】:2015-12-24 04:13:37
【问题描述】:
我几天来一直在尝试使用 Python 的新 print 格式。为了研究这个问题,我已经剪切并粘贴了几个书籍示例。
print '{0} and {1}'.format('spam', 'eggs')
即使这个例子也有效果:
print '{0} and {1}'.format('spam', 'eggs')
^
SyntaxError: invalid syntax
发生了什么事?
【问题讨论】:
-
你用的是什么版本的python?如果您使用的是 python 3,则必须将
print作为函数调用:docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function -
您使用的是 Python 3 吗? Python 3 需要在参数周围加上括号。
标签: python printing format output