The Python language community experienced a fracturing in 2008 when it released Python 3.0. Python 3.0 was a new major version of Python, which means that code written in earlier versions of Python might not run as expected, or at all, using the new version. Many developers did not want to update their code to use the new version, and as a result it took a long time for many third-party libraries to be updated to be compatible with Python 3.
As we finish 2018, most of this history is behind us. Python 2 will no longer be supported after the year 2020, which means it will not be updated as security vulnerabilities are found. This has been an important incentive for third-party library authors, and so the most significant libraries have Python 3 equivalents. This means any new project being written in Python is most likely being written in Python 3. We here at Codecademy love Python 3, and we think you will too.
What's the Difference Between Python 2 and 3?
Even though Python 3 introduced breaking changes to the Python language, many of these changes are fairly straightforward. As a student of Python, some of the aspects of the new version may make more sense or build better programming habits than the old version. That's a good thing. Here are some of the changes to keep in mind:
print()is a function, and takes an argument in parentheses. This makes it more consistent with everything else in Python—old
print()is a normal built-in function.
- Integer division in Python 2 necessarily returned an integer. If you calculated
10 / 8Python would assume that, since you didn't use a decimal place in either operand, you wanted the result to be a number without a decimal. It would perform the division and then "truncate" off the decimal place, effectively rounding down the result to
1. In Python 3 all division returns a floating point number (a number with a decimal point), so
10 / 8would return the expected (and accurate) value of
- Python 3 strings are Unicode by default. An at-length discussion of string encoding is out of the question in this blog post, but the upshot is that a program written in Python 3 won't freak out when attempting to handle characters not on an English-language keyboard. So you won't have to add extra wrangling code when your coworker Ørn Üsterman joins, and you can feel free to write a program that displays emojis 😉.
- Many built-in functions in Python 3 that used to return lists return iterators instead. Lists can use a lot of memory, but an iterator only grabs the information as needed. This means that code like
for number in range(50000), which would first build a list with 50,000 elements in Python 2, won't slow you down at all in Python 3.
Why Should I Take Python 3 Instead of Python 2?
The Python 3 course has been completely rewritten and updated with our learners in mind. If you're just getting started, or you want your progress in the Python course to match up with or the Data Science or Computer Science path, we recommend starting with Python 3.
The syntax differences between Python 3 and Python 2 are fairly small in the greater scheme of things. If you've started Python 2 already and you want to continue, feel free to do so. You'll be able to pick up on the differences quickly. Feel free to use this blog post as your guide!
Why is Python 3 Pro-exclusive?
Python 3 is Pro-exclusive because it's a new course, and it's integral to Codecademy's Pro Paths for both Computer Science and Data Science. Python 2 and 3 aren't so different and learning Python 2 will give you most of the skills required to pick up on Python 3 easily. If you only want to use the free product, switching to Python 2 will still help you learn the basics.