Syntax Error in Python 3: Printing Strings
When attempting to print a string using the print statement in Python 3, you might encounter a syntax error. The following error message indicates that the syntax of the print statement is incorrect:
SyntaxError: invalid syntax
Problem:
The specific syntax error occurs when the print statement is used in the following format:
print "hello World"
This syntax is not valid in Python 3.
Solution:
In Python 3, the print statement has been modified to become a function. This change requires you to include parentheses when using the print statement, as follows:
print("Hello World")
By making this modification, you ensure that the syntax of the print statement is correct and that the string will be printed to the console.
The above is the detailed content of Why Am I Getting a SyntaxError When Printing Strings in Python 3?. For more information, please follow other related articles on the PHP Chinese website!