Difference between revisions 6547 and 26997 on bnwikibooks



indexmodules |next |previous | Python v3.0.1 documentation » What’s New in Python »
What’s New In Python 3.0
Author:	Guido van Rossum
Release:	3.0.1
Date:	February 14, 2009
(contracted; show full)
Print Is A Function
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!
Note:
(contracted; show full)This Page
Show Source
Quick search
  
Enter search terms or a module, class or function name.

indexmodules |next |previous | Python v3.0.1 documentation » What’s New in Python »
© Copyright 1990-2009, Python Software Foundation. Last updated on Feb 14, 2009. Created using Sphinx 0.6.