Let's first start with the choice between python2 and python3
The question that many people who are new to Python struggle with is: should I choose to learn python2 or python3?
To which the answer is: decisively Python3 ! (Recommended learning: Python video tutorials)
However, there are still many white people who are still hesitant to learn Python2: why do people still recommend me to learn Python2?
In fact, there are no more than some of the following reasons:
1. Both Python and Pip have more downloads of 2 than 3, so 2 is still dominant!
Re! There are a number of reasons why 2 is downloaded more than 3, but one of the most important is that Python 2 is still installed by default on the majority of operating systems (Linux distributions.) People are inert, and many of them just use 2 because they don't want to bother with it. But it's a fact that 2 is going down and 3 is going up. Embracing the future is the way to go.
2. Python 2 and 3 are incompatible; if you learn 3, you have to learn 2.
Python provides a number of libraries that allow you to write code that is compatible with both 3 and 2 in a matter of minutes, and all you have to do is bring in a couple of packages, with little or no modification to your code. If you have to use 2 as a last resort, and you have a foundation in 3, you'll be able to get up and running with 2 in no time at all, with very little additional learning required.
3. Many libraries are still in Python 2 and not available in Python 3.
Re! To the person who said that, how long has it been since you've been following Python? so out of touch.
According to the latest statistics from py3readiness, 345 of the top 360 most popular (and most downloaded) libraries on Pip now support Python 3!
python3_readiness.png
Of these, there are only 15 (about 4%) libraries left that don't support Python 3. How obsessed are you to wait until you're at 100% to use 3?
How special can your job be? Do you have to use 2 to do it? And even if you do, what do you need to worry about when you can use virtualenv, conda, and other mature tools to set up another 2 environment on your machine in minutes that's perfectly compatible with 3?
Embrace Python 3! Life is short, I use Python 3.
Choosing Python 3.6 or Python 3.7
Python 3.7 has been released. Currently, Python users mainly use Python 3.6 and Python 2.7, so is it time to switch to Python 3.7?
The first thing you need to know about Python 3.7 is that it's an update to Python 3.6, and the official Python description of what's new in 3.7 is linked below:
/3/whatsnew/3.
The most important thing to note is that 3.7 is almost completely syntactically compatible with 3.6, except for the following:
Backwards incompatible syntax changes:
async and await are now reserved keywords.
This passage, which points out that the only incompatibility of 3.7 with 3.6 is that async and await have become reserved keywords in the Python language.
What do you mean?
It's that the words async and await, like import, for, and while, are keywords that the system reserves for special purposes.
This means that in Python 3.7 you can't use names that define variables, functions, and so on.
For example, I define variables and functions like the following:
async = 1 def await(): pass
It runs fine with Python 3.6, but in Python 3.7 it gives the following error
SyntaxError: invalid syntax
How to choose?
So if your project is currently using Python 3.6 and you have a large project, I personally recommend that you don't rush to move to 3.7. I don't know if your project code and the code of the third-party libraries you rely on have been tested for compatibility with 3.7, after all, 3.7 just came out.
For example, White Moon Black Feather wrote this post on July 13, 2018, and I found that the installation of the Python API driver library for postgresql databases, psycopg2, was problematic on Python 3.7.
pip execution for 3.7
pip install psycopg2-binary
The installation fails with the message Error: pg_config executable not found
And 3.6 pip installs with no problems.
So, we'd better wait until 3.7 is in common use before we switch over.
It's time to move to Python 3.7, unless there are new features in Python 3.7 that your project is particularly eager to use. If that's the case, be sure to do a test that covers the old code well enough to prevent problems when you get it up and running.
What about with Python 2.7?
If the project is currently running Python 2.7, it's mostly a matter of migrating between Python 2 and Python 3, and the syntax is a bit different.
If you have a long project lifecycle, it is recommended that you upgrade to Python3 at the right time. After all, Python2 will not be officially maintained in 2020, so it will be a problem if there are any security holes or other problems. Or if there are third-party libraries that work well, they may not have a version of Python2, and that's even more problematic.
If you decide to upgrade your project from Python2 to Python3, you can start by upgrading to Python3.6, because 3.6 is still widely supported in the industry. You can upgrade to Python 3.6 later, when 3.7 is more widely supported.
I small add: recently learn python read a lot of python3 articles are recommended to use python3.6, we move together.