Home >Backend Development >Python Tutorial >Why Am I Getting a Syntax Error When Printing in Python 3?
Understanding the Syntax Error in Python 3 Print Statements
Encountering a syntax error while printing a string in Python 3 can be perplexing. To resolve this issue, let's delve into the underlying reason.
In Python 3, a significant change was introduced in how the print statement is used. In previous versions of Python, print was a special statement. However, in Python 3, it was converted into a function.
As a result, in Python 3, you must now include parentheses after the print statement to pass in the arguments you want to print. For example:
print("Hello World")
This modification ensures that the print function is called correctly and prevents the syntax error you were encountering. In Python 3, the primary purpose of parentheses is to differentiate between function calls and statements. By adding parentheses, you are explicitly indicating that you are calling the print function and passing in the specified string.
By following this updated syntax, you can successfully print strings in Python 3 and avoid the syntax error you encountered.
The above is the detailed content of Why Am I Getting a Syntax Error When Printing in Python 3?. For more information, please follow other related articles on the PHP Chinese website!