Which Python version are we learniing, Python 2 or Python 3?
Python 2 in the old course. Pro courses may be Python 3, but not the free ones.
Are th edifferences big in those 2 languages? ( Can someone code in python 3 if he knows python 2?)
Yes, you can take your version 2 learning and practice into version 3. Some differences are subtle, others not.
One aspect of Python 3 we can put into practice in Python 2 exercises is the
print() function syntax. In Python 2, print is a construct, but in Python 3 it is a function so the parens are always required. We can use the parens in version 2 with no effect, and build a good habit for going forward.
Python 3 has deprecated
raw_input() in favor of
input(), but that is not a change we can make in version 2 code since it opens an attack vector. In version 2,
input() is equivalent of
eval(raw_input()) which further study will reveal is a security vulnerability. Version 3 fixes this. Bottom line, do not use
input() in version 2 code.
In version 3
reduce() has been shuffled into
from functools import reduce
but you will read that this function is kind of frowned upon. Still handy, though.
In version 2,
filter() return a list, but in version 3 they return an iterator, not a list. We need to use the
list() constructor to store as a list.
>>> type (range(1, 10)) <class 'range'> >>> print (range(1, 10)) range(1, 10) >>> print (list(range(1, 10))) [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> map(lambda x: x ** 2, range(1, 10)) <map object at 0x02E6F510> >>> list(map(lambda x: x ** 2, range(1, 10))) [1, 4, 9, 16, 25, 36, 49, 64, 81] >>> filter(lambda x: not x % 2, range(1, 10)) <filter object at 0x02E6F550> >>> list(filter(lambda x: not x % 2, range(1, 10))) [2, 4, 6, 8] >>>
As expected, we can still use
range() in for loops, no recasting required. Internally
next() on the iterator.
As far as I’ve noticed the pro course ‘Learn Python’ is still in python 2.7 as well.
I’m not sure if any other courses connected to it inside of the catalog branch out though.