python2和python3的不同

在输出方面

  Old: print "The answer is", 2*2

  New: print("The answer is", 2*2)

  Old: print x, # Trailing comma suppresses newline

  New: print(x, end=" ") # Appends a space instead of a newline

  Old: print # Prints a newline

  New: 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)!

猜你喜欢

转载自www.cnblogs.com/Aaron12/p/8858835.html
今日推荐