mirror of
https://github.com/python/cpython.git
synced 2025-11-13 15:40:05 +00:00
Undo changes accidentally reverted in de8787029fe4.
This commit is contained in:
parent
b548d49f65
commit
006d907afc
2 changed files with 19 additions and 11 deletions
|
|
@ -292,13 +292,14 @@ ordering of the objects in the dictionary.
|
||||||
Applying :func:`iter` to a dictionary always loops over the keys, but
|
Applying :func:`iter` to a dictionary always loops over the keys, but
|
||||||
dictionaries have methods that return other iterators. If you want to iterate
|
dictionaries have methods that return other iterators. If you want to iterate
|
||||||
over values or key/value pairs, you can explicitly call the
|
over values or key/value pairs, you can explicitly call the
|
||||||
:meth:`~dict.values` or :meth:`~dict.items` methods to get an appropriate iterator.
|
:meth:`~dict.values` or :meth:`~dict.items` methods to get an appropriate
|
||||||
|
iterator.
|
||||||
|
|
||||||
The :func:`dict` constructor can accept an iterator that returns a finite stream
|
The :func:`dict` constructor can accept an iterator that returns a finite stream
|
||||||
of ``(key, value)`` tuples:
|
of ``(key, value)`` tuples:
|
||||||
|
|
||||||
>>> L = [('Italy', 'Rome'), ('France', 'Paris'), ('US', 'Washington DC')]
|
>>> L = [('Italy', 'Rome'), ('France', 'Paris'), ('US', 'Washington DC')]
|
||||||
>>> dict(iter(L))
|
>>> dict(iter(L)) #doctest: +SKIP
|
||||||
{'Italy': 'Rome', 'US': 'Washington DC', 'France': 'Paris'}
|
{'Italy': 'Rome', 'US': 'Washington DC', 'France': 'Paris'}
|
||||||
|
|
||||||
Files also support iteration by calling the :meth:`~io.TextIOBase.readline`
|
Files also support iteration by calling the :meth:`~io.TextIOBase.readline`
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,8 @@ are always available. They are listed here in alphabetical order.
|
||||||
|
|
||||||
Without an argument, an array of size 0 is created.
|
Without an argument, an array of size 0 is created.
|
||||||
|
|
||||||
|
See also :ref:`binaryseq` and :ref:`typebytearray`.
|
||||||
|
|
||||||
|
|
||||||
.. _func-bytes:
|
.. _func-bytes:
|
||||||
.. function:: bytes([source[, encoding[, errors]]])
|
.. function:: bytes([source[, encoding[, errors]]])
|
||||||
|
|
@ -135,6 +137,8 @@ are always available. They are listed here in alphabetical order.
|
||||||
|
|
||||||
Bytes objects can also be created with literals, see :ref:`strings`.
|
Bytes objects can also be created with literals, see :ref:`strings`.
|
||||||
|
|
||||||
|
See also :ref:`binaryseq`, :ref:`typebytes`, and :ref:`bytes-methods`.
|
||||||
|
|
||||||
|
|
||||||
.. function:: callable(object)
|
.. function:: callable(object)
|
||||||
|
|
||||||
|
|
@ -688,6 +692,8 @@ are always available. They are listed here in alphabetical order.
|
||||||
*sentinel*, :exc:`StopIteration` will be raised, otherwise the value will
|
*sentinel*, :exc:`StopIteration` will be raised, otherwise the value will
|
||||||
be returned.
|
be returned.
|
||||||
|
|
||||||
|
See also :ref:`typeiter`.
|
||||||
|
|
||||||
One useful application of the second form of :func:`iter` is to read lines of
|
One useful application of the second form of :func:`iter` is to read lines of
|
||||||
a file until a certain line is reached. The following example reads a file
|
a file until a certain line is reached. The following example reads a file
|
||||||
until the :meth:`readline` method returns an empty string::
|
until the :meth:`readline` method returns an empty string::
|
||||||
|
|
@ -708,7 +714,7 @@ are always available. They are listed here in alphabetical order.
|
||||||
:noindex:
|
:noindex:
|
||||||
|
|
||||||
Rather than being a function, :class:`list` is actually a mutable
|
Rather than being a function, :class:`list` is actually a mutable
|
||||||
sequence type, as documented in :ref:`typesseq`.
|
sequence type, as documented in :ref:`typesseq-list` and :ref:`typesseq`.
|
||||||
|
|
||||||
|
|
||||||
.. function:: locals()
|
.. function:: locals()
|
||||||
|
|
@ -1082,7 +1088,7 @@ are always available. They are listed here in alphabetical order.
|
||||||
:noindex:
|
:noindex:
|
||||||
|
|
||||||
Rather than being a function, :class:`range` is actually an immutable
|
Rather than being a function, :class:`range` is actually an immutable
|
||||||
sequence type, as documented in :ref:`typesseq`.
|
sequence type, as documented in :ref:`typesseq-range` and :ref:`typesseq`.
|
||||||
|
|
||||||
|
|
||||||
.. function:: repr(object)
|
.. function:: repr(object)
|
||||||
|
|
@ -1207,7 +1213,8 @@ are always available. They are listed here in alphabetical order.
|
||||||
.. function:: str(object='')
|
.. function:: str(object='')
|
||||||
str(object[, encoding[, errors]])
|
str(object[, encoding[, errors]])
|
||||||
|
|
||||||
Return a string version of an object, using one of the following modes:
|
Return a :ref:`string <textseq>` version of an object, using one of the
|
||||||
|
following modes:
|
||||||
|
|
||||||
If *encoding* and/or *errors* are given, :func:`str` will decode the
|
If *encoding* and/or *errors* are given, :func:`str` will decode the
|
||||||
*object* which can either be a byte string or a character buffer using
|
*object* which can either be a byte string or a character buffer using
|
||||||
|
|
@ -1230,11 +1237,9 @@ are always available. They are listed here in alphabetical order.
|
||||||
Objects can specify what ``str(object)`` returns by defining a :meth:`__str__`
|
Objects can specify what ``str(object)`` returns by defining a :meth:`__str__`
|
||||||
special method.
|
special method.
|
||||||
|
|
||||||
For more information on strings see :ref:`typesseq` which describes sequence
|
For more information on strings and string methods, see the :ref:`textseq`
|
||||||
functionality (strings are sequences), and also the string-specific methods
|
section. To output formatted strings, see the :ref:`string-formatting`
|
||||||
described in the :ref:`string-methods` section. To output formatted strings,
|
section. In addition, see the :ref:`stringservices` section.
|
||||||
see the :ref:`string-formatting` section. In addition see the
|
|
||||||
:ref:`stringservices` section.
|
|
||||||
|
|
||||||
|
|
||||||
.. function:: sum(iterable[, start])
|
.. function:: sum(iterable[, start])
|
||||||
|
|
@ -1311,7 +1316,7 @@ are always available. They are listed here in alphabetical order.
|
||||||
:noindex:
|
:noindex:
|
||||||
|
|
||||||
Rather than being a function, :class:`tuple` is actually an immutable
|
Rather than being a function, :class:`tuple` is actually an immutable
|
||||||
sequence type, as documented in :ref:`typesseq`.
|
sequence type, as documented in :ref:`typesseq-tuple` and :ref:`typesseq`.
|
||||||
|
|
||||||
|
|
||||||
.. function:: type(object)
|
.. function:: type(object)
|
||||||
|
|
@ -1344,6 +1349,8 @@ are always available. They are listed here in alphabetical order.
|
||||||
...
|
...
|
||||||
>>> X = type('X', (object,), dict(a=1))
|
>>> X = type('X', (object,), dict(a=1))
|
||||||
|
|
||||||
|
See also :ref:`bltin-type-objects`.
|
||||||
|
|
||||||
|
|
||||||
.. function:: vars([object])
|
.. function:: vars([object])
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue