mirror of
https://github.com/python/cpython.git
synced 2025-11-03 03:22:27 +00:00
bpo-18558: Clarify glossary entry for "Iterable" (#3732)
This commit is contained in:
parent
b1d1c422cc
commit
0bf287b6e0
2 changed files with 10 additions and 2 deletions
|
|
@ -535,7 +535,10 @@ Glossary
|
||||||
iterables include all sequence types (such as :class:`list`, :class:`str`,
|
iterables include all sequence types (such as :class:`list`, :class:`str`,
|
||||||
and :class:`tuple`) and some non-sequence types like :class:`dict`,
|
and :class:`tuple`) and some non-sequence types like :class:`dict`,
|
||||||
:term:`file objects <file object>`, and objects of any classes you define
|
:term:`file objects <file object>`, and objects of any classes you define
|
||||||
with an :meth:`__iter__` or :meth:`__getitem__` method. Iterables can be
|
with an :meth:`__iter__` method or with a :meth:`__getitem__` method
|
||||||
|
that implements :term:`Sequence` semantics.
|
||||||
|
|
||||||
|
Iterables can be
|
||||||
used in a :keyword:`for` loop and in many other places where a sequence is
|
used in a :keyword:`for` loop and in many other places where a sequence is
|
||||||
needed (:func:`zip`, :func:`map`, ...). When an iterable object is passed
|
needed (:func:`zip`, :func:`map`, ...). When an iterable object is passed
|
||||||
as an argument to the built-in function :func:`iter`, it returns an
|
as an argument to the built-in function :func:`iter`, it returns an
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,12 @@ ABC Inherits from Abstract Methods Mixin
|
||||||
.. class:: Iterable
|
.. class:: Iterable
|
||||||
|
|
||||||
ABC for classes that provide the :meth:`__iter__` method.
|
ABC for classes that provide the :meth:`__iter__` method.
|
||||||
See also the definition of :term:`iterable`.
|
|
||||||
|
Checking ``isinstance(obj, Iterable)`` detects classes that are registered
|
||||||
|
as :class:`Iterable` or that have an :meth:`__iter__` method, but it does
|
||||||
|
not detect classes that iterate with the :meth:`__getitem__` method.
|
||||||
|
The only reliable way to determine whether an object is :term:`iterable`
|
||||||
|
is to call ``iter(obj)``.
|
||||||
|
|
||||||
.. class:: Collection
|
.. class:: Collection
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue