27
loading...
This website collects cookies to deliver better user experience
Python2: print "The answer is", 2*2
Python3: print("The answer is", 2*2)
Python2: print x, # The comma at the end suppresses the line feed
Python3: print(x, end=" ") # Adds a space instead of a line feed
Python2: print # Prints a line feed
Python3: print() # We need to call the function!
Python2: print >>sys.stderr, "fatal error"
Python3: print("fatal error", file=sys.stderr)
Python2: print (x, y) # print repr((x, y))
Python3: print((x, y)) # Not to be confused with print(x, y)!
print("There are <", 2**32, "> possibilities!", sep="")
There are <4294967296> possibilities!
The dict.keys(), dict.items() and dict.values() dictionary methods return "mappings" instead of lists. For example, it no longer works:
k = d.keys();
k.sort().
Use k = sorted(d).
The dict.iterkeys(), dict.iteritems() and dict.itervalues() methods are no longer supported.
map() and filter() return iterators. If you really need a list, a quick fix would be list(map(...)), but often the best fix would be to use list generators (especially when the original code uses lambda expressions), or rewrite the code so that it doesn't need a list as such. It is especially difficult that map() causes side effects of the function; the correct transformation is to use a loop (creating a list is just wasteful).
range() now behaves like xrange(), but works with values of any size. xrange() no longer exists.
zip() returns an iterator.