Old: print "The answer is", 2*2New: print("The answer is", 2*2)Old: print x, # Trailing comma suppresses newlineNew: print(x, end=" ") # Appends a space instead of a newline
Old: print# Prints a newlineNew: print() # You must call the function!
Old: print >>sys.stderr, "fatal error"New: print("fatal error", file=sys.stderr)
Old: print (x, y) # prints repr((x, y))New: print((x, y)) # Not the same as print(x, y)!
python3 不在自动支持空白空格
The print() function doesn’t support the “softspace” feature of the old print statement. For example, in Python 2.x, print "A\n", "B" would write "A\nB\n"; but in Python 3.0, print("A\n", "B") writes "A\n B\n".