mirror of https://github.com/python/cpython.git
Neaten-up the named tuple docs
This commit is contained in:
parent
d08a8ebf2a
commit
15b5e55b48
|
@ -364,8 +364,8 @@ they add the ability to access fields by name instead of position index.
|
||||||
method which lists the tuple contents in a ``name=value`` format.
|
method which lists the tuple contents in a ``name=value`` format.
|
||||||
|
|
||||||
The *fieldnames* are a single string with each fieldname separated by whitespace
|
The *fieldnames* are a single string with each fieldname separated by whitespace
|
||||||
and/or commas (for example 'x y' or 'x, y'). Alternatively, *fieldnames*
|
and/or commas, for example ``'x y'`` or ``'x, y'``. Alternatively, *fieldnames*
|
||||||
can be a sequence of strings (such as ['x', 'y']).
|
can be a sequence of strings such as ``['x', 'y']``.
|
||||||
|
|
||||||
Any valid Python identifier may be used for a fieldname except for names
|
Any valid Python identifier may be used for a fieldname except for names
|
||||||
starting with an underscore. Valid identifiers consist of letters, digits,
|
starting with an underscore. Valid identifiers consist of letters, digits,
|
||||||
|
@ -373,7 +373,7 @@ they add the ability to access fields by name instead of position index.
|
||||||
a :mod:`keyword` such as *class*, *for*, *return*, *global*, *pass*, *print*,
|
a :mod:`keyword` such as *class*, *for*, *return*, *global*, *pass*, *print*,
|
||||||
or *raise*.
|
or *raise*.
|
||||||
|
|
||||||
If *verbose* is true, will print the class definition.
|
If *verbose* is true, the class definition is printed just before being built.
|
||||||
|
|
||||||
Named tuple instances do not have per-instance dictionaries, so they are
|
Named tuple instances do not have per-instance dictionaries, so they are
|
||||||
lightweight and require no more memory than regular tuples.
|
lightweight and require no more memory than regular tuples.
|
||||||
|
@ -527,7 +527,7 @@ a fixed-width print format::
|
||||||
Point: x=14.000 y= 0.714 hypot=14.018
|
Point: x=14.000 y= 0.714 hypot=14.018
|
||||||
|
|
||||||
Another use for subclassing is to replace performance critcal methods with
|
Another use for subclassing is to replace performance critcal methods with
|
||||||
faster versions that bypass error-checking and that localize variable access::
|
faster versions that bypass error-checking::
|
||||||
|
|
||||||
class Point(namedtuple('Point', 'x y')):
|
class Point(namedtuple('Point', 'x y')):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
Loading…
Reference in New Issue