In a recent post, I gave some advice on how to learn Python for free. At the top of the post I lightly touched on the Python 2 vs Python 3 debate. I code in Python 2 mostly because that’s what I learned first and my interactions with Google and a hedge fund in NYC have shown me that Python 2 is still very much alive in the wild.
That said, I think the writing is on the wall for Python 2. First, Python core is dropping support for Python 2.7 in January 2020. That gives you a little over a year to utilize some of the Python 2 classes I mentioned in that post before you need to transition to Python 3. However, if you are going to use Pandas (and you shouldn’t do any real data work in Python without it) you’ll probably want to transition earlier; both Pandas and Numpy are stopping 2.7 releases on December 31, 2018. That’s just over four months from now! (Where has this year gone?)
Generally the switch isn’t a big deal. Most of the core code is the same and it’s not like you need to learn a new language. However, there are some interesting differences that can wreak havoc in your code if you don’t know about them. My favorite difference is that native division in Python 3 returns a float rather than an int:
print 7/5 print -7/5 # In Python 2 1 -2 # In Python 3 1.4 -1.4
My transition begins today. Any new projects I do will be in Python 3 but I want to keep my old stuff in Python 2 for now. Anyone making the switch with similar needs for both Python 2 and 3 should check out the many virtual environment options. You can learn about those differences in the top answer to this Stack Overflow post.