Which One Should I Learn As A Beginner: Python 2 Or Python 3?

By Kimberly Cook |Email | Dec 31, 2018 | 25551 Views

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.

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

A LITTLE HISTORY OF PYTHON 2 VS 3
Let's begin with a brief timeline of Python 2 vs 3 usages.

  • 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.

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.

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.

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.

AS A BEGINNER, SHOULD I LEARN PYTHON 2 OR 3 IN 2018?
The simple answer? Learn the latest version (which at time of writing in 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.

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.

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.

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

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

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:
  • 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

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"

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 to programme 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!

Source: HOB