python2和python3的不同

时间:2021-03-30 18:16:25

在输出方面

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

重新加载

  Old: reload(filename)

  New: import importlib

          importlib.reload(filename)