@@ -1249,37 +1249,30 @@ Python does not enforce these consistency rules.
1249
1249
Membership test operations
1250
1250
--------------------------
1251
1251
1252
- The operators :keyword: `in ` and :keyword: `not in ` test for collection
1253
- membership. ``x in s `` evaluates to true if *x * is a member of the collection
1254
- *s *, and false otherwise. ``x not in s `` returns the negation of ``x in s ``.
1255
- The collection membership test has traditionally been bound to sequences; an
1256
- object is a member of a collection if the collection is a sequence and contains
1257
- an element equal to that object. However, it make sense for many other object
1258
- types to support membership tests without being a sequence. In particular,
1259
- dictionaries (for keys) and sets support membership testing.
1260
-
1261
- For the list and tuple types, ``x in y `` is true if and only if there exists an
1262
- index *i * such that either ``x is y[i] `` or ``x == y[i] `` is true.
1263
-
1264
- For the Unicode and string types, ``x in y `` is true if and only if *x * is a
1265
- substring of *y *. An equivalent test is ``y.find(x) != -1 ``. Note, *x * and *y *
1266
- need not be the same type; consequently, ``u'ab' in 'abc' `` will return
1267
- ``True ``. Empty strings are always considered to be a substring of any other
1268
- string, so ``"" in "abc" `` will return ``True ``.
1269
-
1270
- .. versionchanged :: 2.3
1271
- Previously, *x * was required to be a string of length ``1 ``.
1252
+ The operators :keyword: `in ` and :keyword: `not in ` test for membership. ``x in
1253
+ s `` evaluates to ``True `` if *x * is a member of *s *, and ``False `` otherwise.
1254
+ ``x not in s `` returns the negation of ``x in s ``. All built-in sequences and
1255
+ set types support this as well as dictionary, for which :keyword: `in ` tests
1256
+ whether the dictionary has a given key. For container types such as list, tuple,
1257
+ set, frozenset, dict, or collections.deque, the expression ``x in y `` is equivalent
1258
+ to ``any(x is e or x == e for e in y) ``.
1259
+
1260
+ For the string and bytes types, ``x in y `` is ``True `` if and only if *x * is a
1261
+ substring of *y *. An equivalent test is ``y.find(x) != -1 ``. Empty strings are
1262
+ always considered to be a substring of any other string, so ``"" in "abc" `` will
1263
+ return ``True ``.
1272
1264
1273
1265
For user-defined classes which define the :meth: `__contains__ ` method, ``x in
1274
- y `` is true if and only if ``y.__contains__(x) `` is true.
1266
+ y `` returns ``True `` if ``y.__contains__(x) `` returns a true value, and
1267
+ ``False `` otherwise.
1275
1268
1276
1269
For user-defined classes which do not define :meth: `__contains__ ` but do define
1277
- :meth: `__iter__ `, ``x in y `` is true if some value ``z `` with ``x == z `` is
1270
+ :meth: `__iter__ `, ``x in y `` is `` True `` if some value ``z `` with ``x == z `` is
1278
1271
produced while iterating over ``y ``. If an exception is raised during the
1279
1272
iteration, it is as if :keyword: `in ` raised that exception.
1280
1273
1281
1274
Lastly, the old-style iteration protocol is tried: if a class defines
1282
- :meth: `__getitem__ `, ``x in y `` is true if and only if there is a non-negative
1275
+ :meth: `__getitem__ `, ``x in y `` is `` True `` if and only if there is a non-negative
1283
1276
integer index *i * such that ``x == y[i] ``, and all lower integer indices do not
1284
1277
raise :exc: `IndexError ` exception. (If any other exception is raised, it is as
1285
1278
if :keyword: `in ` raised that exception).
0 commit comments