0

Which is good to learn.Python 2.7 or Python 3

7th Nov 2016, 4:56 PM
Sachin Kamath
Sachin Kamath - avatar
3 Réponses
+ 3
I'd say python 3, since it's newer.
8th Nov 2016, 12:29 PM
Alex Schrichte
Alex Schrichte - avatar
+ 1
They are pretty similar, either is good to start. Recent tutorials may consider Python 3 but there are a lot of resource available on Python 2, starting with the free e-book "Think into Python" (plus Python 2 is still the default in many Linux distributions). Apps and online classes nowadays probably prefer Python 3 (Sololearn, Datacamp, and so on). If you write code for Python 2.7 there is a tool to convert it to Python 3 (named 2to3 or something like that). Some differences between Python 2.7 and 3 that you are likely to run into when you begin coding. 1. Python 2.7 has a unique division operator / for both integer and floating division (1/2 is 0 while 1.0/2, 1/2., 1./2.0, ... is 0.5) while Python 3 has / for floating division and // for integer division. 2. In Python 2 print is a statement, while in Python 3 it is a function. As a function you could, e.g, replace print with another function and in general you are more flexible. Pro tip: if you want to write code compatible with both Python 2 and 3 always put round brackets around your argument, as in print(x). They are useless (but harmless) in Python 2 and required in Python 3. 3. In Python 3 the range () function creates a generator like the xrange () function does in Python 2 (whilst range () creates a list).
7th Nov 2016, 9:43 PM
Giulio Pellitta
Giulio Pellitta - avatar
0
If you just started with learning Python, you should go with Python3, because it is future proof and you already got many useful resources. Python2 will get updates until 2020.
13th Nov 2016, 7:51 AM
ItsBoris