Incompatible Changes From Python2 to Python3

Python3 is there. We will need to switch from Python2 to Python3 sooner or later.

Here are some repetitive mistakes I have made (or keep making), when I do the switch.

Trying to combine a full list from my hands-on experience. Please leave me comments for your input!

Similar Posts:

  • 1. More strict rule when print for Python3
print 3/2 # OK in Python2

print 3/2 # error in Pythone3
# SyntaxError: Missing parentheses in call to 'print'

  • 2. xrange doesn’t work in Python3 now.
# In python2, Below works.
for i in xrange(3):
# But in python3, we get below exception.
# NameError: name 'xrange' is not defined

  • 3. In python3, you might get float when you’re expecting integer
print(num/2) # In python2, it's 1

print(num/2) # In python3, it's 1.5

See more:


Share It, If You Like It.

Leave a Reply

Your email address will not be published.