diff options
author | Guido van Rossum <guido@python.org> | 2007-09-06 14:46:41 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-09-06 14:46:41 (GMT) |
commit | dff1c31fb44deea78d28df6eccab07193edce3bb (patch) | |
tree | 3ed026d719a95a74f8140d3ad120bf5146dceb08 /Doc | |
parent | 67ced426bc92c8c53987843589be1c9c089ee9bb (diff) | |
download | cpython-dff1c31fb44deea78d28df6eccab07193edce3bb.zip cpython-dff1c31fb44deea78d28df6eccab07193edce3bb.tar.gz cpython-dff1c31fb44deea78d28df6eccab07193edce3bb.tar.bz2 |
In response to issue 1101, place vastly more emphasis on the new print()
function.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/whatsnew/3.0.rst | 59 |
1 files changed, 42 insertions, 17 deletions
diff --git a/Doc/whatsnew/3.0.rst b/Doc/whatsnew/3.0.rst index cf2caf2..afe842d 100644 --- a/Doc/whatsnew/3.0.rst +++ b/Doc/whatsnew/3.0.rst @@ -79,6 +79,48 @@ and fast errors; it's the subtle behavioral changes in code that remains syntactically valid that trips people up. I'm also omitting changes to rarely used features.) +* 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! + + Notes about the ``print()`` function: + + * 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"``. + + * Initially, you'll be finding yourself typing the old ``print x`` + a lot in interactive mode. Time to retrain your fingers to type + ``print(x)`` instead! + + * When using the ``2to3`` source-to-source conversion tool, all + ``print`` statements are autmatically converted to ``print()`` + function calls, so this is mostly a non-issue for larger projects. + * Python 3.0 uses strings and bytes instead of the Unicode strings and 8-bit strings. This means that pretty much all code that uses Unicode, encodings or binary data in any way has to change. The @@ -109,19 +151,6 @@ changes to rarely used features.) * Code that unconditionally strips the trailing ``L`` from the ``repr()`` of a long integer will chop off the last digit instead. -* 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"``. - -* Also, ``print`` and ``print (x, y)`` behave differently without - warning: the former used to add a newline in 2.x, but does nothing - in 3.0; the latter used to print the ``repr()`` of a tuple in 2.x, - but prints the individual values in 3.0. - -* You'll be finding yourself typing ``print x`` a lot in interactive - mode. Time to retrain your fingers. :-) - Strings and Bytes ================= @@ -241,10 +270,6 @@ language and built-in functions. * PEP 3104: ``nonlocal`` statement. Using ``nonlocal x`` you can now assign directly to a variable in an outer (but non-global) scope. -* PEP 3105: ``print`` is now a function. Keyword arguments - ``file=sys.stdout``, ``sep=" "`` and ``end="\n"`` let you customize - it. - * PEP 3111: ``raw_input()`` renamed to ``input()``. That is, the new ``input()`` function reads a line from ``sys.stdin`` and returns it with the trailing newline stripped. It raises ``EOFError`` if the |