Original: https://blog.csdn.net/zylove2010/article/details/79594000
There are big differences between python2.x and python3.x. Except for the big changes in the names of dependent packages, the main differences are summarized as follows:
1) print function
In Python3, the parentheses of the print functionis required, Python2 is optional.
2) The keyboard reads the input
Python3 only retains the input() function, and the input data is all processed as a string; Python2 also supports the row_input() functionstrong>, the input() function in the process of processing the input number, if the input number is enclosed in quotation marks, it will be processed as a string, otherwise it will be processed as a number.
3) Divide
In Python3, the division operation is converted into a floating-point numeric type for processing, and the division operation in Python2 performs the rounding operation.
4) Unicode representation
Python2 data is saved in Unicode encoding format, a string marked with U is required, and Python3 is stored in Unicode encoding format by default.
5) xrange() function
There are range() and xrange() functions in Python2, where xrange() returns the size of the list on demand to save memory usage. In Python3, the xrange() function was renamed to range() function, and slicing is supported in Python 3.2 and later.
6) next() and .next() functions
Python2 supports both functions, and Python3 only supports the next() function.
7) Python2 code to 3 tool: 2to3
The 2to3.py script will usually be installed in the tools/scripts folder.It reads Python2.x source code and applies a series of fixes to turn it into valid Python3.x code; eg: 2to3 -w test.py.