What does “SyntaxError: Missing parentheses in call to 'print'” mean in Python?

前端 未结 8 1247
天命终不由人
天命终不由人 2020-11-21 09:02

When I try to use a print statement in Python, it gives me this error:

>>> print \"Hello, World!\"
  File \"\", line 1
            


        
8条回答
  •  南笙
    南笙 (楼主)
    2020-11-21 09:51

    If your code should work in both Python 2 and 3, you can achieve this by loading this at the beginning of your program:

    from __future__ import print_function   # If code has to work in Python 2 and 3!
    

    Then you can print in the Python 3 way:

    print("python")
    

    If you want to print something without creating a new line - you can do this:

    for number in range(0, 10):
        print(number, end=', ')
    

提交回复
热议问题