Python 3 or Python 2: Which Should I Learn?

As many Python beginners, I wonder with which version of Python they should start. Perhaps the I should start with the version that best Python books for beginners are written in, and figure out the differences later on.

What if as beginner I want to start a new project and have the choice to pick Python version? The End Of Life date for Python 2.7 has been moved five years into the future, to 2020 and realistically speaking it is quite possible that in 2020 I will be using some other language, not Python. From the other point of view it would be better to study the newest version of the language. At least I have a look at the major differences between Python 2 and Python 3 to avoid common pitfalls when writing the code on the whiteboard during technical Python interview. The most visible (difference) is probably the way the “print” statement works. It is definitely the most widely known change, but still it is worth mentioning. The print statement in Python 2 has been replaced with a print() function in Python 3, with keyword arguments to replace most of the special syntax of the old print statement

Python 2 :

print "Python", python_version()
print "How to pass Python 2 Interview?"

Python 3 :

print("Python, python_version())
print("How to pass Python 3 Interview?")

Somehow I like an old statement mainly because it allowed me to type two less characters (ie, the parentheses), but the good explanation of the change to the interviewer would without doubt put me in the front of other job candidates.

No comments:

Post a Comment