Kaydet (Commit) 14bb28aa authored tarafından Georg Brandl's avatar Georg Brandl

Fix a few markup glitches.

üst ffefd5a8
...@@ -127,16 +127,17 @@ Basic usage of the :meth:`str.format` method looks like this:: ...@@ -127,16 +127,17 @@ Basic usage of the :meth:`str.format` method looks like this::
We are the knights who say "Ni!" We are the knights who say "Ni!"
The brackets and characters within them (called format fields) are replaced with The brackets and characters within them (called format fields) are replaced with
the objects passed into the format method. The number in the brackets refers to the objects passed into the :meth:`~str.format` method. The number in the
the position of the object passed into the format method. :: brackets refers to the position of the object passed into the
:meth:`~str.format` method. ::
>>> print '{0} and {1}'.format('spam', 'eggs') >>> print '{0} and {1}'.format('spam', 'eggs')
spam and eggs spam and eggs
>>> print '{1} and {0}'.format('spam', 'eggs') >>> print '{1} and {0}'.format('spam', 'eggs')
eggs and spam eggs and spam
If keyword arguments are used in the format method, their values are referred to If keyword arguments are used in the :meth:`~str.format` method, their values
by using the name of the argument. :: are referred to by using the name of the argument. ::
>>> print 'This {food} is {adjective}.'.format( >>> print 'This {food} is {adjective}.'.format(
... food='spam', adjective='absolutely horrible') ... food='spam', adjective='absolutely horrible')
...@@ -157,7 +158,7 @@ truncates Pi to three places after the decimal. ...@@ -157,7 +158,7 @@ truncates Pi to three places after the decimal.
The value of PI is approximately 3.142. The value of PI is approximately 3.142.
Passing an integer after the ``':'`` will cause that field to be a minimum Passing an integer after the ``':'`` will cause that field to be a minimum
number of characters wide. This is useful for making tables pretty.:: number of characters wide. This is useful for making tables pretty. ::
>>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 7678} >>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 7678}
>>> for name, phone in table.items(): >>> for name, phone in table.items():
...@@ -178,7 +179,7 @@ square brackets ``'[]'`` to access the keys :: ...@@ -178,7 +179,7 @@ square brackets ``'[]'`` to access the keys ::
Jack: 4098; Sjoerd: 4127; Dcab: 8637678 Jack: 4098; Sjoerd: 4127; Dcab: 8637678
This could also be done by passing the table as keyword arguments with the '**' This could also be done by passing the table as keyword arguments with the '**'
notation.:: notation. ::
>>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678} >>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678}
>>> print 'Jack: {Jack:d}; Sjoerd: {Sjoerd:d}; Dcab: {Dcab:d}'.format(**table) >>> print 'Jack: {Jack:d}; Sjoerd: {Sjoerd:d}; Dcab: {Dcab:d}'.format(**table)
...@@ -356,9 +357,9 @@ shorter than writing equivalent :keyword:`try`\ -\ :keyword:`finally` blocks:: ...@@ -356,9 +357,9 @@ shorter than writing equivalent :keyword:`try`\ -\ :keyword:`finally` blocks::
>>> f.closed >>> f.closed
True True
File objects have some additional methods, such as :meth:`isatty` and File objects have some additional methods, such as :meth:`~file.isatty` and
:meth:`truncate` which are less frequently used; consult the Library Reference :meth:`~file.truncate` which are less frequently used; consult the Library
for a complete guide to file objects. Reference for a complete guide to file objects.
.. _tut-pickle: .. _tut-pickle:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment