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

前端 未结 8 1340
天命终不由人
天命终不由人 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=', ')
    
    0 讨论(0)
  • 2020-11-21 09:52

    In Python 3, you can only print as:

    print("STRING")
    

    But in Python 2, the parentheses are not necessary.

    0 讨论(0)
提交回复
热议问题