【发布时间】:2016-07-08 15:27:32
【问题描述】:
我使用 Python 2.7 已经有一段时间了。 突然,我的 print 语句出现错误,看起来我现在应该使用 Python 3.x 语法。
print 'hello world'
File "<ipython-input-462-d05d0c8adf1f>", line 1
print 'hello world'
^
SyntaxError: invalid syntax
print('hello world')
hello world
我再次确认我仍在运行 2.x Python 版本:
import sys
print (sys.version)
2.7.12 |Anaconda 2.3.0 (64-bit)| (default, Jun 29 2016, 11:07:13) [MSC v.1500 64 bit (AMD64)]
我最近对我的 Python 环境所做的唯一更改是将 matplotlib 从 1.4 更新到 1.5,但老实说,我不能说问题是否从更新的确切时刻开始。
任何帮助将不胜感激(请让我知道我的系统上还需要哪些其他信息)
【问题讨论】:
-
你有
from __future__ import print_function吗?
标签: python python-2.7