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".
python2.x 与python3.x 的区别所有的区别都来源于python官方文档,建议朝python3.x版本转换的童鞋都看下官方文档https://docs.python.org/3/whatsnew/index.htmlPrint Is A Function主要差别Old: print "The answer is", 2*2New: print("The answer is", 2*2