Skip to content

Instantly share code, notes, and snippets.

What would you like to do?

Из основного:

  • print в 3.х не keyword, а функция.
Feature Python 2.x Python 3.x
print print "a string" или print("a string") print("a string")
integer division 3 / 2 # 1 3 // 2 # 1
float division 3.0 / 2 # 1.5 3.0 / 2 # 1.5
user input raw_input("> ") input("> ")


Далее d — это словарь (dictionary).

Feature Python 2.x Python 3.x
iterating through dict for key in d.iterkeys(): for key in d:
iterating through dict for value in d.itervalues(): for value in d.values():
iterating through dict for (key, value) in d.iteritems(): for (key, value) in d.items():
dict as a list keylist = d.keys() keylist = list(d)
dict as a list valuelist = d.values() valuelist = list(d.values())


Feature Python 2.x Python 3.x
xrange for i in xrange(10): for i in range(10):
range for i in range(10): for i in list(range(10)):
map new = map(f, old) new = list(map(f, old))
filter new = filter(f, old) new = list(filter(f, old))


Feature Python 2.x Python 3.x
raising exceptions raise ValueError, "something is wrong" raise ValueError("something is wrong")
catching exceptions except ValueError, e: except ValueError as e:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.