mirror of
https://github.com/python/cpython.git
synced 2025-09-27 18:59:43 +00:00
Issue 6722: Improve the namedtuple examples.
This commit is contained in:
parent
086f30815c
commit
0ef956f997
1 changed files with 5 additions and 1 deletions
|
@ -586,11 +586,15 @@ they add the ability to access fields by name instead of position index.
|
||||||
.. versionchanged:: 3.1
|
.. versionchanged:: 3.1
|
||||||
Added support for *rename*.
|
Added support for *rename*.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
.. doctest::
|
.. doctest::
|
||||||
:options: +NORMALIZE_WHITESPACE
|
:options: +NORMALIZE_WHITESPACE
|
||||||
|
|
||||||
|
>>> # Basic example
|
||||||
|
>>> Point = namedtuple('Point', 'x y')
|
||||||
|
>>> p = Point(x=10, y=11)
|
||||||
|
|
||||||
|
>>> # Example using the verbose option to print the class definition
|
||||||
>>> Point = namedtuple('Point', 'x y', verbose=True)
|
>>> Point = namedtuple('Point', 'x y', verbose=True)
|
||||||
class Point(tuple):
|
class Point(tuple):
|
||||||
'Point(x, y)'
|
'Point(x, y)'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue