Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
2eee1d4d
Kaydet (Commit)
2eee1d4d
authored
Eki 22, 2009
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#6324: membership test tries iteration via __iter__.
üst
6c14e587
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
5 deletions
+16
-5
datamodel.rst
Doc/reference/datamodel.rst
+8
-4
expressions.rst
Doc/reference/expressions.rst
+8
-1
No files found.
Doc/reference/datamodel.rst
Dosyayı görüntüle @
2eee1d4d
...
@@ -1888,12 +1888,16 @@ implemented as an iteration through a sequence. However, container objects can
...
@@ -1888,12 +1888,16 @@ implemented as an iteration through a sequence. However, container objects can
supply the following special method with a more efficient implementation, which
supply the following special method with a more efficient implementation, which
also does not require the object be a sequence.
also does not require the object be a sequence.
.. method:: object.__contains__(self, item)
.. method:: object.__contains__(self, item)
Called to implement membership test operators. Should return true if *item* is
Called to implement membership test operators. Should return true if *item*
in *self*, false otherwise. For mapping objects, this should consider the keys
is in *self*, false otherwise. For mapping objects, this should consider the
of the mapping rather than the values or the key-item pairs.
keys of the mapping rather than the values or the key-item pairs.
For objects that don't define :meth:`__contains__`, the membership test first
tries iteration via :meth:`__iter__`, then the old sequence iteration
protocol via :meth:`__getitem__`, see :ref:`this section in the language
reference <membership-test-details>`.
.. _sequence-methods:
.. _sequence-methods:
...
...
Doc/reference/expressions.rst
Dosyayı görüntüle @
2eee1d4d
...
@@ -1068,6 +1068,8 @@ Comparison of objects of the same type depends on the type:
...
@@ -1068,6 +1068,8 @@ Comparison of objects of the same type depends on the type:
another one is made arbitrarily but consistently within one execution of a
another one is made arbitrarily but consistently within one execution of a
program.
program.
.. _membership-test-details:
The operators :keyword:`in` and :keyword:`not in` test for collection
The operators :keyword:`in` and :keyword:`not in` test for collection
membership. ``x in s`` evaluates to true if *x* is a member of the collection
membership. ``x in s`` evaluates to true if *x* is a member of the collection
*s*, and false otherwise. ``x not in s`` returns the negation of ``x in s``.
*s*, and false otherwise. ``x not in s`` returns the negation of ``x in s``.
...
@@ -1092,7 +1094,12 @@ string, so ``"" in "abc"`` will return ``True``.
...
@@ -1092,7 +1094,12 @@ string, so ``"" in "abc"`` will return ``True``.
For user-defined classes which define the :meth:`__contains__` method, ``x in
For user-defined classes which define the :meth:`__contains__` method, ``x in
y`` is true if and only if ``y.__contains__(x)`` is true.
y`` is true if and only if ``y.__contains__(x)`` is true.
For user-defined classes which do not define :meth:`__contains__` and do define
For user-defined classes which do not define :meth:`__contains__` but do define
:meth:`__iter__`, ``x in y`` is true if some value ``z`` with ``x == z`` is
produced while iterating over ``y``. If an exception is raised during the
iteration, it is as if :keyword:`in` raised that exception.
Lastly, the old-style iteration protocol is tried: if a class defines
:meth:`__getitem__`, ``x in y`` is true if and only if there is a non-negative
:meth:`__getitem__`, ``x in y`` is true if and only if there is a non-negative
integer index *i* such that ``x == y[i]``, and all lower integer indices do not
integer index *i* such that ``x == y[i]``, and all lower integer indices do not
raise :exc:`IndexError` exception. (If any other exception is raised, it is as
raise :exc:`IndexError` exception. (If any other exception is raised, it is as
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment