< !-- Digital window verification 001 -->

What Should I Learn as a Beginner: Python 2 or Python 3?

| Get awesome (and free) stuff here


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, in 2018, it’s more of a no-brainer: Python 3 is the clear winner for new learners or those wanting to update tudemheir 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

Want to master Python?

Then download my list of favorite Python learning resources.

Don't worry. I'll never, ever spam you! Powered by ConvertKit

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 2 vs 3 2018 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.

Computer

3. There is better Unicode support in Python 3

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.

Instagram

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

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.

Code

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.

Don't worry. I'll never, ever spam you! Powered by ConvertKit

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 three Python course options to consider.

Python

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.

The Complete Python 3 Course

Why pick this particular course: Upon completion of the course you’ll have the skills to build your own real-life applications

Course facts:

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.

Python for Everybody Specialization

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:

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

Course facts:

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”

Head back to the table of contents »


Conclusion

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!