summaryrefslogtreecommitdiffstats
path: root/Doc/tutorial
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2009-09-01 08:13:16 (GMT)
committerGeorg Brandl <georg@python.org>2009-09-01 08:13:16 (GMT)
commit7baf625bab07456074a0ef9c8493ea1ed72c338e (patch)
treeba30d134b7fedcd126de9e935872e34561ad7767 /Doc/tutorial
parent2686039b761e061c4ba9edd8666092a2643a65de (diff)
downloadcpython-7baf625bab07456074a0ef9c8493ea1ed72c338e.zip
cpython-7baf625bab07456074a0ef9c8493ea1ed72c338e.tar.gz
cpython-7baf625bab07456074a0ef9c8493ea1ed72c338e.tar.bz2
Merged revisions 74613,74615,74619-74620,74622 via svnmerge from
svn+ssh://svn.python.org/python/branches/py3k ................ r74613 | georg.brandl | 2009-09-01 09:34:27 +0200 (Di, 01 Sep 2009) | 1 line #6814: remove traces of xrange(). ................ r74615 | georg.brandl | 2009-09-01 09:42:40 +0200 (Di, 01 Sep 2009) | 9 lines Recorded merge of revisions 74614 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r74614 | georg.brandl | 2009-09-01 09:40:54 +0200 (Di, 01 Sep 2009) | 1 line #6813: better documentation for numberless string formats. ........ ................ r74619 | georg.brandl | 2009-09-01 10:02:03 +0200 (Di, 01 Sep 2009) | 1 line #6754: remove old struct member nb_inplace_divide. ................ r74620 | georg.brandl | 2009-09-01 10:03:26 +0200 (Di, 01 Sep 2009) | 1 line #6732: fix return value of module init function in example. ................ r74622 | georg.brandl | 2009-09-01 10:11:14 +0200 (Di, 01 Sep 2009) | 73 lines Merged revisions 74542,74544-74548,74550,74554-74555,74578,74588,74590,74603,74616-74618,74621 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r74542 | georg.brandl | 2009-08-23 23:28:56 +0200 (So, 23 Aug 2009) | 1 line Restore alphabetic order. ........ r74544 | georg.brandl | 2009-08-24 19:12:30 +0200 (Mo, 24 Aug 2009) | 1 line #6775: fix python.org URLs in README. ........ r74545 | georg.brandl | 2009-08-24 19:14:29 +0200 (Mo, 24 Aug 2009) | 1 line #6772: mention utf-8 as utf8 alias. ........ r74546 | georg.brandl | 2009-08-24 19:20:40 +0200 (Mo, 24 Aug 2009) | 1 line #6725: spell "namespace" consistently. ........ r74547 | georg.brandl | 2009-08-24 19:22:05 +0200 (Mo, 24 Aug 2009) | 1 line #6718: fix example. ........ r74548 | georg.brandl | 2009-08-24 19:24:27 +0200 (Mo, 24 Aug 2009) | 1 line #6677: mention "deleting" as an alias for removing files. ........ r74550 | georg.brandl | 2009-08-24 19:48:40 +0200 (Mo, 24 Aug 2009) | 1 line #6677: note that rmdir only removes empty directories. ........ r74554 | georg.brandl | 2009-08-27 20:59:02 +0200 (Do, 27 Aug 2009) | 1 line Typo fix. ........ r74555 | georg.brandl | 2009-08-27 21:02:43 +0200 (Do, 27 Aug 2009) | 1 line #6787: reference fix. ........ r74578 | tarek.ziade | 2009-08-29 15:33:21 +0200 (Sa, 29 Aug 2009) | 1 line fixed #6801: symmetric_difference_update also accepts pipe ........ r74588 | georg.brandl | 2009-08-30 10:35:01 +0200 (So, 30 Aug 2009) | 1 line #6803: fix old name. ........ r74590 | georg.brandl | 2009-08-30 13:51:53 +0200 (So, 30 Aug 2009) | 1 line #6801: fix copy-paste oversight. ........ r74603 | georg.brandl | 2009-08-31 08:38:29 +0200 (Mo, 31 Aug 2009) | 1 line other -> others where multiple arguments are accepted. ........ r74616 | georg.brandl | 2009-09-01 09:46:26 +0200 (Di, 01 Sep 2009) | 1 line #6808: clarification. ........ r74617 | georg.brandl | 2009-09-01 09:53:37 +0200 (Di, 01 Sep 2009) | 1 line #6765: hint that log(x, base) is not very sophisticated. ........ r74618 | georg.brandl | 2009-09-01 10:00:47 +0200 (Di, 01 Sep 2009) | 1 line #6810: add a link to the section about frame objects instead of just a description where to find it. ........ r74621 | georg.brandl | 2009-09-01 10:06:03 +0200 (Di, 01 Sep 2009) | 1 line #6638: fix wrong parameter name and markup a class. ........ ................
Diffstat (limited to 'Doc/tutorial')
-rw-r--r--Doc/tutorial/classes.rst12
-rw-r--r--Doc/tutorial/inputoutput.rst15
2 files changed, 18 insertions, 9 deletions
diff --git a/Doc/tutorial/classes.rst b/Doc/tutorial/classes.rst
index 7ef4153..4e166d1 100644
--- a/Doc/tutorial/classes.rst
+++ b/Doc/tutorial/classes.rst
@@ -51,8 +51,8 @@ need for two different argument passing mechanisms as in Pascal.
.. _tut-scopes:
-Python Scopes and Name Spaces
-=============================
+Python Scopes and Namespaces
+============================
Before introducing classes, I first have to tell you something about Python's
scope rules. Class definitions play some neat tricks with namespaces, and you
@@ -87,7 +87,7 @@ attributes is possible. Module attributes are writable: you can write
:keyword:`del` statement. For example, ``del modname.the_answer`` will remove
the attribute :attr:`the_answer` from the object named by ``modname``.
-Name spaces are created at different moments and have different lifetimes. The
+Namespaces are created at different moments and have different lifetimes. The
namespace containing the built-in names is created when the Python interpreter
starts up, and is never deleted. The global namespace for a module is created
when the module definition is read in; normally, module namespaces also last
@@ -381,9 +381,9 @@ data attribute, its class is searched. If the name denotes a valid class
attribute that is a function object, a method object is created by packing
(pointers to) the instance object and the function object just found together in
an abstract object: this is the method object. When the method object is called
-with an argument list, it is unpacked again, a new argument list is constructed
-from the instance object and the original argument list, and the function object
-is called with this new argument list.
+with an argument list, a new argument list is constructed from the instance
+object and the argument list, and the function object is called with this new
+argument list.
.. _tut-remarks:
diff --git a/Doc/tutorial/inputoutput.rst b/Doc/tutorial/inputoutput.rst
index 549a922..dbb56f6 100644
--- a/Doc/tutorial/inputoutput.rst
+++ b/Doc/tutorial/inputoutput.rst
@@ -126,12 +126,12 @@ with zeros. It understands about plus and minus signs::
Basic usage of the :meth:`str.format` method looks like this::
- >>> print('We are the {0} who say "{1}!"'.format('knights', 'Ni'))
+ >>> print('We are the {} who say "{}!"'.format('knights', 'Ni'))
We are the knights who say "Ni!"
The brackets and characters within them (called format fields) are replaced with
-the objects passed into the :meth:`~str.format` method. The number in the
-brackets refers to the position of the object passed into the
+the objects passed into the :meth:`~str.format` method. A number in the
+brackets can be used to refer to the position of the object passed into the
:meth:`~str.format` method. ::
>>> print('{0} and {1}'.format('spam', 'eggs'))
@@ -152,6 +152,15 @@ Positional and keyword arguments can be arbitrarily combined::
other='Georg'))
The story of Bill, Manfred, and Georg.
+``'!a'`` (apply :func:`ascii`), ``'!s'`` (apply :func:`str`) and ``'!r'``
+(apply :func:`repr`) can be used to convert the value before it is formatted::
+
+ >>> import math
+ >>> print('The value of PI is approximately {}.'.format(math.pi))
+ The value of PI is approximately 3.14159265359.
+ >>> print('The value of PI is approximately {!r}.'.format(math.pi))
+ The value of PI is approximately 3.141592653589793.
+
An optional ``':'`` and format specifier can follow the field name. This allows
greater control over how the value is formatted. The following example
truncates Pi to three places after the decimal.