+ 1

Why did they change python2s print to print() in python3? Which syntax/function do you prefer?

Why did they change print?

12th Dec 2016, 7:36 PM
Nick Bowling
Nick Bowling - avatar
2 Answers
+ 1
From what I hear, it sounds like Guido thinks he made a mistake when he didn't make print a function when he created Python.
12th Dec 2016, 8:01 PM
Nick Bowling
Nick Bowling - avatar
+ 1
""" The print statement has been replaced with a print() function, with keyword arguments to replace most of the special syntax of the old print statement (PEP 3105). Examples: 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)! You can also customize the separator between items, e.g.: print("There are <", 2**32, "> possibilities!", sep="") which produces: There are <4294967296> possibilities! """ ref: Python 3.0 docs
12th Dec 2016, 8:52 PM
Yunus USLU
Yunus USLU - avatar