In the past, there was a bit of a debate in the coding community about which Python version was the best one to learn: Python 2 vs Python 3 (or, specifically, Python 2.7 vs 3.5).
Now, it’s more of a no-brainer: Python 3 is the clear winner for new learners or those wanting to update their skills. Here, we’ll cover why Python 3 is better, and why companies have been moving from Python 2 to 3 en masse.
That said, there are still some situations where picking up Python 2 might be advantageous. Or you may just want to learn a little of the history and the differences between Python 2 and 3 for curiosity’s sake.
So, without further ado, let’s take a look at some of the major differences between Python 2 vs Python 3–plus where to learn Python 3 programming as a beginner.
Disclosure: I’m a proud affiliate for some of the resources mentioned in this article. If you buy a product through my links on this page, I may get a small commission for referring you. Thanks!
Table of Contents
- History of Python 2 vs 3
- What are the main Python 2 vs 3 2018 differences?
- Why companies are moving from Python 2 to 3?
- As a beginner, should I learn Python 2 or 3 in 2018?
- When it makes sense to learn Python 2?
- Where to start learning Python 3?
- Conclusion
Want to master Python?
Then download my list of favorite Python learning resources.
A little history of Python 2 vs 3
Let’s begin with a brief timeline of Python 2 vs 3 usage.
- Python 2.0 was first released in 2000. Its latest version, 2.7, was released in 2010.
- Python 3.0 was released in 2008. Its newest version, 3.6, was released in 2016, and version 3.7 is currently in development.
- Although Python 2.7 is still widely used, Python 3 adoption is growing quickly. In 2016, 71.9% of projects used Python 2.7, but by 2017, it had fallen to 63.7%. This signals that the programming community is turning to Python 3–albeit gradually–when developing real-world applications.
- Notably, on January 1, 2018, Python 2.7 will “retire” and no longer be maintained. (The clock is literally ticking!)
Next, we’ll move on to the differences for Python 2 vs 3 in 2018.
Head back to the table of contents »
What are the main Python vs Python 3 differences?
There are plenty of differences between these Python programming versions, but here are five of the main ones.
1. Python 2 is legacy, Python 3 is the future.
Since Python 2 has been the most popular version for over a decade and a half, it is still entrenched in the software at certain companies.
However, since more companies are moving from Python 2 to 3, someone who wants to learn Python programming for beginners may wish to avoid spending time on a version that is becoming obsolete.
2. Python 2 and Python 3 have different (sometimes incompatible) libraries
Since Python 3 is the future, many of today’s developers are creating libraries strictly for use with Python 3.
Similarly, many older libraries built for Python 2 are not forwards-compatible.
You may be able to port a 2.x library to 3.x., but this can be difficult and complicated; it’s definitely not a “Python for beginners” type of activity.
3. There is better Unicode support in Python 3
Another key difference between difference between Python 2 and 3 is that in Python 3, text strings are Unicode by default. In Python 2, strings are stored as ASCII by default–you have to add a “u” if you want to store strings as Unicode in Python 2.x.
This is important because Unicode is more versatile than ASCII. Unicode strings can store foreign language letters, Roman letters and numerals, symbols, emojis, etc., offering you more choices.
4. Python 3 has improved integer division
In Python 2, if you write a number without any digits after the decimal point, it rounds your calculation down to the nearest whole number.
For example, if you’re trying to perform the calculation 5 divided by 2, and you type 5 / 2, the result will be 2 due to rounding. You would have to write it as 5.0 / 2.0 to get the exact answer of 2.5.
However, in Python 3, the expression 5 / 2 will return the expected result of 2.5 without having to worry about adding those extra zeroes.
This is one example of how Python 3 syntax can be more intuitive, making it easier for newcomers to learn Python programming.
5. The two versions have different print statement syntaxes
This is only a syntactical difference–and some may consider it trivial–so it doesn’t affect the functionality of Python. That said, it is still a big and visible difference you should know about.
Essentially, in Python 3, the print statement has been replaced with a print () function.
For example, in Python 2 it is print “hello” but in Python 3 it is print (“hello”).
If you’re going to learn Python programming for the first time, it shouldn’t affect you much. But if you started with Python 2, the change may trip you up a few times.
To learn more differences between Python 2 and 3, check out The Python Wiki.
Head back to the table of contents »
Why companies are moving from Python 2 to 3
As mentioned earlier, most companies are still using Python 2 for legacy reasons, but more and more companies are using Python 3, or beginning to make the switch from 2 to 3.
So, let’s look at Instagram and Facebook–two companies that have switched from Python 2 to 3 or are in the process of doing so–and why they chose to do so.
In 2017, Instagram migrated the majority of their Python code base from Python 2.7 to Python 3.
Why they use it:
- Python is not traditionally a typed language, but Python v3.5 supports typing, which removes development conflicts when working new pieces of code.
- Each newer version of Python continues to get faster runtime. Meanwhile, nobody’s currently working to make Python 2.7 work faster.
- Community support is better with Python 3.
Facebook is currently in the process of upgrading their infrastructure and handlers from Python 2 to Python 3.4.
Why they use it:
- According to RealPython, “The ease of using Python libraries means that the production engineers don’t have to write or maintain as much code, allowing them to focus on getting improvements live. It also ensures that the infrastructure of Facebook is able to scale efficiently.”
- Watch this talk on YouTube for more information about the changing culture of Python at Facebook.
Head back to the table of contents »
As a beginner, should I learn Python 2 or 3 in 2018?
The simple answer? Learn the latest version (which at time of writing is Python 3.7.0).
Some of the changes made in Python 3 have actually made it easier for beginners to understand, so it’s the best way to learn Python for the first time.
This is the best way to future-proof yourself as more and more programmers pursue Python 3 adoption. Keep in mind that Python 2.7 will no longer be supported after 2020, so dedicating effort to learning it at this point won’t make sense for most folks. I say “most” because there are a few types of people who might need it.
Head back to the table of contents »
When it makes sense to learn Python 2
Here are some situations where you might need to know Python 2:
- If you want to become a DevOps engineer and work with configuration management tools like Fabric or Ansible, you might have to work with both Python 2 and 3 (because parts of these libraries don’t have full Python 3 support).
- If your company has legacy code written in Python 2, you’ll need to learn to work with that.
- If you have a project that depends on certain third-party software or libraries that can’t be ported to Python 3, you’ll have no choice but to use Python 2 for it.
Luckily, whichever version you start with, it will be fairly easy to transfer your knowledge to the other if needed.
Want to master Python?
Then download my list of favorite Python learning resources.
Head back to the table of contents »
Where to start learning Python 3?
So, if you’ve decided to learn Python 3, the next question is “Where do I learn python for beginners?” Here are some Python course options to consider.
Udemy: The Complete Python 3 Course
What the course covers: All the basics like strings, expressions, loops, functions, exception handling, etc. Great way for someone with zero prior knowledge to learn to code Python.
Why pick this particular course: Upon completion of the course you’ll have the skills to build your own real-life applications
Course facts:
- Course Name: The Complete Python 3 Course: Go from Beginner to Advanced!
- Platform: Udemy
- Course URL: https://learntocodewith.me/complete-python-3
- Instructed by: Ermin Kreponic
- Price: $9.99
- Skill level: Beginner
🔎 Read our full review of Udemy.
Coursera: Programming for Everybody (Getting Started with Python)
What the course covers: Covers core programming tools such as functions and loops, as well as variables to store, retrieve, and calculate information.
Why pick this particular course: 4.8 star rating (out of 38K+ reviews); this course is part of a Coursera specialization so you can continue on to more advanced topics if you want
Course facts:
- Course Name: Programming for Everybody (Getting Started with Python)
- Platform: Coursera
- Course URL: https://learntocodewith.me/getting-started-with-python
- Instructed by: Charles Severance
- Price: 7-day free trial (and then $49 per month)
- Skill level: Beginner
🔎 Read our full review of Coursera.
edX: Introduction to Computer Science and Programming Using Python
What the course covers: Python syntax, simple algorithms, how to think computationally, data structures, and more
Why pick this particular course: Taught by MIT professors; “designed to help people with no prior exposure to computer science or programming learn to think computationally and write programs to tackle useful problems”
Course facts:
- Course Name: Introduction to Computer Science and Programming Using Python
- Platform: edX
- Course URL: https://learntocodewith.me/introduction-to-python
- Instructed by: John Guttag, Eric Grimson, and Ana Bell
- Price: Free
- Skill level: Beginner
🔎 Read our full review of edX.
Zero to Mastery: Complete Python Developer in 2021
What the course covers: Build 12+ real-world Python projects, learn web development, machine learning, object oriented programming, and more
Why pick this particular course: Building real projects that you can use in the real world is essential to learning effectively. Not only can you include these projects on your portfolio, but by building them, you’ll learn hands-on skills that you can use again and again in the future.
Course facts:
- Course Name: Complete Python Developer in 2021
- Platform: Zero to Mastery
- Course URL: https://learntocodewith.me/ztm-complete-python-developer-in-2020
- Instructed by: Andrei Neagoie
- Price: $29/month or $264/year for access to the entire ZTM course library
- Skill level: Beginner
Codecademy: Learn Python 3
What the course covers: Python 3 syntax, functions, control flow, loops, strings, and more
Why pick this particular course: “This course is a great introduction to both fundamental programming concepts and the Python programming language.”
Course facts:
- Course Name: Learn Python 3
- Platform: Codecademy
- Course URL: https://learntocodewith.me/codecademy-learn-python-3
- Price: Free
- Skill level: Beginner
🔎 Read our full review of Codecademy.
Skillshare: Python 3: A Beginners Guide to Python Programming
What the course covers: Everything you need to know as a Python beginner, with 130+ lectures and over 7 hours of video each one detailing a specific aspect of the Python programming language.
Why pick this particular course: You will go from a complete Python beginner, installing Python to creating your own programs.
Course facts:
- Course Name: Python 3: A Beginners Guide to Python Programming
- Platform: Skillshare
- Course URL: https://learntocodewith.me/skillshare-python-3
- Instructed by: Tony Staunton
- Price: $19/month or $99/year (with a 14-day free trial!)
- Skill level: Beginner
Code With Mosh: Complete Python Mastery
What the course covers: Everything you need to program in Python in one course, including 3 real-world projects.
Why pick this particular course: Mosh has taught over nine million people how to code and how to become professional software engineers.
Course facts:
- Course Name: Complete Python Mastery
- Platform: Code With Mosh
- Course URL: https://learntocodewith.me/mosh-python
- Instructed by: Mosh Hamedani
- Price: $149 for lifetime access or $19/month
- Skill level: Beginner
Head back to the table of contents »
Summing up Python 2 vs Python 3
When it comes to Python 2 vs 3 in 2018, Python 3 is the clear winner. Since Python 2 is being phased out by 2020, mass Python 3 adoption is the clear direction of the future.
For beginners, starting out with Python–and especially Python 3–is a great way to learn programming quickly. It’s a diverse and intuitive language and tons of awesome companies like Google, NASA, Facebook, and Spotify are using it!
Plus, the average yearly salary for Python developers comes in at $92,000 per year, so if you learn Python 3, you might find your career prospects looking brighter than ever.
Try out one of the online Python courses above to start learning Python programming today!