What possibilities does Python 2
Python 2 vs. 3: What should I learn as a beginner?
Until recently, there was some debate in the developer community as to which version of Python a beginner should learn: Python 2 or Python 3.
In 2019 this question is basically answered clearly: If you are starting out with Python or want to brush up your skills, you should use Python 3. In this article we want to discuss what Python 3 does better, and why many companies are switching to Python 3 en masse.
However, there are still a few scenarios where using Python 2 can be beneficial. Definitely worth the history of development and differences Python 2 and Python 3 to know.
So let's take a look at what makes Python 2 different from Python 3, and where, as a beginner, you can get a good introduction to programming with Python 3.
The story of Python 2 and Python 3
Here we want to briefly describe some time milestones in the development of Python:
- Python 2.0 was first released in 2000. The latest version, 2.7, was released in 2010.
- Python 3.0 was released in 2008. The latest version, 3.7, was released in 2018. Version 3.8 is currently under development.
- Although Python 2.7 is still heavily used, the trend is clearly towards Python 3. In 2016, 71.9% of all projects were using Python 2.7, but that number had already dropped to 63.7% in 2017. This shows that the programming community is now increasingly using Python 3 for production-ready projects.
- Official support for Python 2 will end in 2020. From then on there will be no more new releases.
Now let's look at some of the current differences between Python 2 and Python 3 (as of 2018):
What are the main differences between Python 2 and 3?
There are some differences between the different versions of Python. Here we want to go into five of the most important ones.
1. Python 2 is the past, Python 3 is the future.
Since Python 2 was the most popular version of Python for over ten years, it is still used by many software developers.
Nevertheless, a beginner should learn Python 3 today. The reason is obvious: if you start from scratch anyway, you shouldn't waste time learning something that will be obsolete in the foreseeable future.
2. Python 2 and Python 3 use libraries, some of which are incompatible with one another.
Since Python 3 is the future standard version of Python, many new libraries are being developed exclusively for Python 3. Some of the libraries developed for Python 2 do not work with Python 3. It is of course possible to convert these libraries, but since this is often difficult, it is usually beyond the capabilities of a Python beginner.
3. Python 3 has better support for Unicode.
All strings in Python 3 are Unicode encoded by default. Python 2 still used the ASCII coding here and Unicode had to be specified explicitly with a "u".
This is important because Unicode is much more diverse than ASCII. Unicode supports characters from non-Arabic fonts, Roman numbers, symbols, emojjis, and much more.
As you can probably guess, the use of Unicode has massive advantages, especially for internationalized applications.
4. Python 3 uses an improved division of integers
If you define two numbers without decimal places in Python 2 and divide the two by one another, the result is rounded to the nearest whole number.
As an example, let's look at dividing 7 by 2. Let's write in Python 2:sum = 7/2
the variable sum contains the number 2. If you want to get the correct result 3.5, you would have to write the code differently:sum = 7.0 / 2.0
This is because Python 2 recognizes the correct data type of the result. Python 3, on the other hand, recognizes that the result is to be treated as a float. This is an example of how Python 3 makes the syntax more intuitive, which makes programming easier, especially for beginners.
5. Python 2 and Python 3 have a different syntax for the print
This difference is purely syntactic and is therefore considered trivial by many. Still, it's one of the biggest and most noticeable differences, and probably one that you'll come across the most.
In Python 3, the print statement was replaced by a print function.
Example:print & quot; 5 & quot;
is valid code in Python 2, but leads to a syntax error in Python 3. There you wouldprint (& quot; 5 & quot;)
Why companies are moving from Python 2 to Python 3
As mentioned earlier, many companies use Python 2 for historical reasons. But more and more have started the change from version 2 to version 3.
Two of these companies are Instagram and Facebook. We want to explore the reasons for this in the following.
Instagram migrated most of its source code from Python 2.7 to Python 3 back in 2017.
Reasons for the change:
- Python is not a statically typed language. However, Python 3.5 supports typing, which can help avoid development conflicts.
- Every new Python version has a more powerful runtime environment, while no one is working on optimizing Python 2.7
- Most of the community has already switched to Python 3, making it easier to get support for any problems.
Facebook is currently working on upgrading their infrastructure from Python 2 to Python 3.4.
Reasons for the change:
- Better support for various libraries means software engineers have less code to write or maintain. This increases productivity and improvements can go live faster.
- Facebook's infrastructure scales more efficiently.
I am a Beginner. Which version of Python should I learn?
As with most programming languages, the question is relatively easy to answer: learn the latest version.
Some of the changes in Python 3 even made it easier to get started with Python. That makes it the best version of Python for beginners.
Sooner or later you will have to make the switch anyway. Support for Python 2 will end in 2020. Therefore, starting at this point makes little sense for most of them. However, there are certain reasons that will still need Python 2.
What are the reasons for learning Python 2?
In the following, we want to list reasons why it can make sense to be familiar with Python 2:
- If you want to become a DevOps Engineer and use configuration tools like Fabric or Ansible, you may have to work with Python 2 and 3, as these tools do not yet fully support Python 3.
- If the company you work for has a large amount of code based on Python 2 and is not (yet) ready to convert the code to Python 3.
- If you have a project that uses external libraries or software that cannot be ported to Python 3.
Fortunately, the differences between the versions are not that glaring, which makes knowledge transfer easier.
When choosing between Python 2 and Python 3, Python 3 is the clear winner. Python 2 will no longer be supported from 2020 and sooner or later everyone will switch to Python 3.
Beginners should start right away with Python 3 and the accompanying tutorials. Python is also a good choice for newbies who have never programmed, as it is very intuitive and yet offers many possibilities. Lots of great companies are using Python 3 - including Google, NASA, Facebook, and Spotify.
Experienced Python developers earn very high salaries. Depending on your knowledge and experience, your salary will be between € 50,000-100,000. This, of course, makes Python attractive as a career springboard.
- Which solution can dissolve carbon?
- Have the Romans arrived in Scotland?
- Gay Pride parades are unnecessary
- Damage magnetic mounts to telephones
- How many courses are available after graduation
- How does my ISP count the data used
- What are the best restaurants in Deoghar
- What's next for modern art
- Is oil actually sent in barrels
- Can a poem ever be bad
- What is hard science
- Are religions the source of languages
- Who is the jazz musician in this photo
- How does war affect the stock market?
- What is a provisioning agent
- Which religious groups don't celebrate Christmas?
- What are the Gryffindor colors
- How do millionaires compensate with bad memories
- Can CBD Relax You
- Are universities strict about TOEFL limits?
- Companies are still buying email lists
- Joseph Smith was a bad person
- How many scales are there in western music
- Why do different people like different songs