Judgment and selection guide of python version

Determine the version of the source code

 Python3.0 is not fully compatible with Python2.0

The grammatical differences between Python 2.0 and Python 3.0 are mainly manifested in the following aspects:

1. Output

Python2.0 uses the print keyword for output, for example: print "Hello";

Python3.0 uses the print() function, such as print("Hello").

2. Input

Python2.0 uses the raw_input() function, for example: name=raw_input("Please enter your name: ");

Python3.0 uses the input() function, for example: name=input("Please enter your name:").

3. The encoding format of the string

By default, Python 2.0 uses ASCII encoding to encode the input string;

By default, Python 3.0 uses Unicode encoding to encode strings.

4. Ways to format strings

Python2.0 uses % placeholders to standardize format output strings, for example: "Hello,%s" % ("World");

Python3.0 uses the format() function, such as: "Hello,{}".format("World").

5. The encoding format of the source file

Python2.0 uses ASCII by default, so when using Chinese, add a line of comments at the beginning of the source file: # - - coding: utf-8 - -;

Python3.0 uses utf-8 by default.

Choice of python version

1. On the issue of large versions, there is a huge difference between Python3.x and Python2.x. Python2 has been eliminated by the times. It has been more than ten years since the official release of Python3 in 2008. The current mainstream is Python3, so zero Basic beginners should not consider Python2 when they start learning. After all, Python2.7, the final version of the Python2 era, has already been officially stopped for technical support. Unless you learn Python to maintain old code developed many years ago, there is no need Choose Python2 for learning.

2.Python3 has also released multiple versions in recent years, such as Python3.6, 3.7, 3.8, 3.9, and 3.10. In general, each minor version has some new features, but the basic syntax and functions are not too big change. A major advantage of Python is that it has a wealth of third-party libraries, and some third-party libraries do not support too new versions, so the newer the better. For general Win7 system users, you can choose 3.6, 3.7, 3.8 versions, 32-bit or 64-bit depends on your system. In addition, Win7 system is not supported since Python3.9, so for Win10 users, you can also choose 3.9 or 3.10. For MacOS users, 3.6-3.10 is fine. (As for the last version number, such as 3.8.8 or 3.8.9, it doesn't matter)

Guess you like

Origin blog.csdn.net/qq_28838891/article/details/126896252