After installing the latest version of the Python 3.x version,
To refer to someone else's code (based on a Python 2.x writing tutorial), to use the print function, when the output is printed, the result is a syntax error with the PRINT function:
Syntaxerror:invalid syntax
This is because the syntax of the Python 2.x upgrade to the Python 3.x,print function is changed, so the code for Python 2.x's print function, which runs in Python 3.x, results in the print function "SyntaxError: Invalid syntax. "
Differences in the syntax of print functions in Python 2.x and Python 3.x
The most concise explanation is:
Python 2.x:print "What to print" without parentheses
Python 3.x:print function ("What to print"), must be enclosed in parentheses
For example, it is:
1. Formatted with no percent sign
Python 2.x:
print"Pyhon 2 can use print string without ()";
Python 3.x:
print("Python3, print must use () to output string");
2. Formatted with percent
Python 2.x:
print"old %s version is %d, print no ()"%("Python"2);
Python 3.x:
print("new %s version is %d, print must have ()"%("Python"3));
Reason for syntax error (syntaxerror:invalid syntax) using the Print function in Python 3.x