在python 3中,我打算在不跳过一行的情况下打印一行:
print('hello', end='')
我收到此错误消息:
print('hello', end='')
^
SyntaxError: invalid syntax
发生了什么?如何更正此错误?
答案 0 :(得分:4)
你绝对确定你使用的是Python 3,而不是偶然地调用Python 2吗?
~ $ python3
Python 3.6.2 (default, Jul 17 2017, 16:44:45)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print('hello', end='')
hello>>>
~ $ python2
Python 2.7.13 (default, Jul 18 2017, 09:17:00)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print('hello', end='')
File "<stdin>", line 1
print('hello', end='')
^
SyntaxError: invalid syntax
>>>