简体   繁体   English

python的Hello World语法错误

[英]Syntax error on hello world with python

The Following hello world example is giving me an error, any help would be useful 以下hello world示例给我一个错误,任何帮助都将有用

print("Hello","World", sep="***")


File "basicio.py", line 9
    print("Hello","World", sep="***")
                              ^
SyntaxError: invalid syntax

您正在python 2解释器中运行python 3代码。

You are using Python2 and and writing Python3 syntax. 您正在使用Python2并正在编写Python3语法。

Just type print "hello, world" 只需输入print "hello, world"

Or use python3 from your prompt. 或在提示下使用python3

print() is for python 3.x, to make it work in python 2.x you need to import it first: print()用于python 3.x,要使其在python 2.x中工作,您需要首先将其导入:

In [3]: from __future__ import print_function

In [4]: print("Hello","World", sep="***")
Hello***World

您的语法对于Python 2.x无效。

Maybe you are using Python 2? 也许您正在使用Python 2? This is Python 3 syntax. 这是Python 3语法。

There are two separate things in python: statements and functions. python中有两件事:语句和函数。 In python 2, print is a statement. 在python 2中,print是一条语句。 In python 3 onwards, they turned print into a function, and allowed it to take arguments such as ' sep '. 从python 3开始,他们将print变成一个函数,并允许它接受诸如' sep '之类的参数。 You are using python 2, therefore if you have to use this extra functionality, upgrade to python 3. 您正在使用python 2,因此如果必须使用此额外功能,请升级到python 3。

For more information on the change in print, check this out. 有关在打印变化的更多信息,请查看出来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM