As someone who taught myself Python, I figured a common question that a lot of new learners probably have is “what version of Python should I learn?” Naturally, I put together this article to answer that question.
In short, I recommend picking up the latest version of Python 3. That way, any advice you receive about the language will apply to the current state of the ecosystem. Of course, if you already have certain tools or libraries that you plan to use, it might be a good idea to check which versions of Python they support.
In the remainder of this article, we’ll take a look at the challenges associated with picking a version of Python. Particularly, we’ll compare and contrast the two major versions of the language: Python 2 and Python 3. Then, I’ll share a few potential options before trying to convince you to go with the latest version of Python 3.
Table of Contents
Python Has a Lot of Versions
Perhaps one of the weirdest quirks of Python is the division between the two most recent major versions of the language: 2 and 3. Fortunately, the choice is made a bit easier as the older version is already out the door. However, a large portion of the community is still clinging onto it.
To make matters worse, Python is broken up into several minor versions which can make selecting a version to learn that much harder. For instance, if we decide to go with Python 3, we have almost 10 minor versions to choose from (at the time of writing at least). How do we even begin to navigate this mess?
Luckily, I’ve been where you are right now. In fact, when I first picked up Python in 2017, I was restricted to Python 2 as it was the version we were using for a project. At that time, Python 2 was already nearing its end of life, but that didn’t stop my company from using it. And, I wouldn’t be surprised if they were still using it today.
As a result, I figured I’d put together this article to help you sift through the various versions, so you can decide which one to learn today.
Python 2 Vs. Python 3
Now, before we can choose a version, we need to talk about the differences between Python 2 and Python 3 for just a moment. Don’t worry though! I’m assuming you’re an absolute beginner, so I’ll explain all the jargon.
In the world of arithmetic, there are various types of numbers. For example, there are the natural numbers which are the numbers we use for counting (e.g. 1, 2, 3…). Another set of numbers are the integers which include all the natural numbers as well as their negative counterparts (e.g. -2, -1, 0, 1, 2).
In Python, we can work with these numbers using common arithmetic operations like addition (+) and subtraction (-). In fact, pretty much all of the standard arithmetic operations exist:
- Addition (+)
- Subtraction (-)
- Multiplication (*)
- Division (/)
Unfortunately, arithmetic isn’t as straightforward in Python as you’d think. That’s because numbers aren’t represented as decimals (0 – 9) in the computer; they’re binary (0 & 1). As a result, we have to deal with some of the messiness of binary. For example, integers and real numbers (e.g. 1.5, 3.14, etc.) are represented differently in the computer.
To deal with this problem, Python treats both sets of numbers as separate types: integers and floats. Usually, this isn’t apparent to the user because most of the common operations behave appropriate regardless. In other words, mixing integers and floats causes no problems for addition, subtraction, and multiplication.
Where things get messy is division. After all, if we divide a number in half, we would expect to be able to reconstruct the original number by multiply the result by two. Unfortunately, that’s not true for one specific case: integer division.
In Python 2, division is computed using the division operator (
/). As long as one of the operands is a float, the result will be a float. However, if both operands are integers, we’ll end up with an integer result—even for results that should be floats. For example, one-half will evaluate to zero in Python 2. In other words, the half is thrown out through a process known as truncation.
In Python 3, division is made more intuitive. Now, no matter what numbers we provide to the division operator, we’ll end up with the answer you expect (or at least a close approximation). For example, one-half will properly evaluate to one-half in Python 3.
Unfortunately, this means division is not backwards compatible. If a script relies heavily on integer division in Python 2, it cannot be easily ported to Python 3. Fortunately, Python 3 includes the floor division operator (
//) which allows us to get a similar behavior as Python 2 integer division (at least for positive integers).
In Python, it’s common to want to see what’s happening in a program as it runs. Sometimes, we do this by printing information to the console. For example, we might have a program that asks a user for several numbers. As the user enters each number, we might print a running sum to make sure we’re storing the input correctly.
In Python 2, printing was done using a simple
print "Hello, World!"
Unfortunately, this syntax is a bit unnatural. In particular, it treats
Now, in the latest version of Python, parentheses are required when printing to the user. In Python 2, this is a completely legal syntax. Unfortunately, the reverse is not true for Python 3. As a result, porting code from Python 2 to 3 will require parentheses to be added if they aren’t already.
And Many More!
Up to this point, I’ve listed some of the differences that you’re likely to encounter as a beginner. Unfortunately, there are a ton of other changes that I we haven’t gotten to explore yet. As a result, here are a couple articles that go through even more differences than we had time to cover today:
- The key differences between Python 2.7.x and Python 3.x with examples
- What Should I Learn as a Beginner: Python 2 or Python 3?
In the next section, we’ll talk about what we can do with the information we now know about Python 2 and Python 3.
Choosing a Path
Rather than listing off all the versions of Python with their pros, cons, and features, I figured it might make more sense to present a couple options. Specifically, we’ll look at two general options (Python 2 vs. Python 3) and one more specific option.
Option 1: Choose The Latest Version of Python 3
If you’re interested in learning Python, the best advice I can give is to install the latest version. At the time of writing, that was Python 3.8, but Python 3.9 is right around the corner.
The main reason I advise going with the latest version is that you have almost nothing to lose. In other words, if you’re truly a beginner, it’s unlikely that you’ll run into problems. By the time you know enough to be dangerous, you’ll be able to make the switch to a version that’s right for you.
That said, I should warn you that newer versions of Python almost always have features that aren’t backwards compatible. For example, Python 3.8 has the walrus operator. If you decide to learn and use that part of the language, you’ll have a harder time going back to older versions of the language.
If you’d prefer to use a more stripped down version of the language, then you might be better off with the next option.
Option 2: Choose the “Latest” Version of Python 2
As I mentioned already, Python 2 is no longer supported as of January 1st, 2020. However, that doesn’t mean you can’t download and run it. In fact, the official Python website still lists Python 2.7.18 as an option.
However, the only reason you should opt for Python 2 is if you were stuck on some legacy project using it. And even then, you should try to find a way to upgrade it to Python 3 if possible. Of course, there are a lot of challenges associated with that.
That said, I did mention above that Python 2 is quite a bit more stripped down than Python 3. As a result, you could probably make the case that the language would be better for learning. After all, you wouldn’t get caught up in fancy features like f-strings, walrus operators, and dictionary union operators.
Of course, I couldn’t recommend Python 2 in good conscience. As the Python community continues to move forward, all the etiquette around the language continues to grow and develop. By using Python 2, you won’t be able to educate yourself on the proper idioms and style conventions.
Overall, I wouldn’t recommend Python 2 to anyone unless they just wanted to explore the language for fun.
Option 3: Choose the Version of Python That Matches Your Needs
If you’re new to the community, and you don’t know where to start, I’d definitely recommend grabbing the latest version of Python 3. However, if you already know what you want to use Python for, you might want to do a bit of research first.
Unfortunately, not every library out there is going to support the latest version of Python. For example, PyInstaller does not currently support Python 3.8—at least at the time of writing. Likewise, PyAudio only supports up to Python 3.6.
If you already know what tools you want to learn and use, then you’re constrained by their requirements. At times this can be very frustrating. For example, I’m a big fan of f-strings, but they weren’t introduced until Python 3.6. If I have to use a library that’s using a version of Python that’s older than that, I can’t use them.
This can be particularly frustrating for projects that have to include a new library with these kinds of restrictions. If you’re used to coding in Python 3.8 but suddenly need to drop the version, it’s very possible that portions of the code will need to be updated.
As a result, I recommend looking into the tools you want to use before you pick a Python version. Of course, if you’re just looking to learn the language, there’s no reason to go through all this effort. Just grab the latest version and go.
Whatever version you choose, don’t fret! It’s important to make an informed choice about which Python version you use, but the fact that you’ve decided to learn Python is more important than anything.
Again, if you’re not sure where to start, head on over to Python official website and pick up the latest version of the language. Then, once you have Python downloaded and installed, we can begin talking about what software tools you should start using.
In the meantime, here are a few articles to get you looking at some of the cool features of Python:
Likewise, here are some resources from the folks over on Amazon (ad):
- Effective Python: 90 Specific Ways to Write Better Python
- Python Tricks: A Buffet of Awesome Python Features
- Python Programming: An Introduction to Computer Science
Finally, if you’d like to support this site, here’s a list of ways you can do just that. This includes links to my YouTube channel, newsletter, and Patreon. Otherwise, thanks for stopping by! I appreciate it.