简体   繁体   中英

Syntax error on hello world with python

The Following hello world example is giving me an error, any help would be useful

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.

Just type print "hello, world"

Or use python3 from your prompt.

print() is for python 3.x, to make it work in python 2.x you need to import it first:

In [3]: from __future__ import print_function

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

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

Maybe you are using Python 2? This is Python 3 syntax.

There are two separate things in python: statements and functions. In python 2, print is a statement. In python 3 onwards, they turned print into a function, and allowed it to take arguments such as ' sep '. You are using python 2, therefore if you have to use this extra functionality, upgrade to python 3.

For more information on the change in print, check this out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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