Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
d201153d
Commit
d201153d
authored
Sep 06, 2007
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
In response to issue 1101, place vastly more emphasis on the new print()
function.
parent
c2fc4dc2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
17 deletions
+42
-17
Doc/whatsnew/3.0.rst
Doc/whatsnew/3.0.rst
+42
-17
No files found.
Doc/whatsnew/3.0.rst
View file @
d201153d
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment