This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Comparison operators in Python Tutorial 5.7
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: docs@python, miss-islington, realjanpaulus, rhettinger
Priority: normal Keywords: patch

Created on 2022-01-05 16:11 by realjanpaulus, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30504 merged rhettinger, 2022-01-09 17:03
PR 30509 merged miss-islington, 2022-01-10 02:02
Messages (7)
msg409782 - (view) Author: Jan (realjanpaulus) Date: 2022-01-05 16:11
In chapter 5.7 in the official Python tutorial (see: https://docs.python.org/3/tutorial/datastructures.html), there is the following paragraph:

"The comparison operators in and not in check whether a value occurs (does not occur) in a sequence. The operators is and is not compare whether two objects are really the same object. All comparison operators have the same priority, which is lower than that of all numerical operators."

I believe that "in" and "not in" are rather membership operators than comparison operators. I think a differentiation of operator types in one or two sentences would be helpful.
msg409799 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2022-01-05 19:14
It may seem weird, but a "membership operator" is a kind of "comparison operator".¹  They can even participate in chaining, 'a < b in s < c` is equivalent to `(a < b) and (b in s) and (b < c)`. 

I'm propose this new wording to mention the concept of "membership":

"The comparison operators `in` and `not in` are membership tests that determine whether a value is in (or not in) a container."

¹ https://docs.python.org/3/reference/expressions.html#comparisons
msg409806 - (view) Author: Jan (realjanpaulus) Date: 2022-01-05 21:16
I really like this solution because it mentions the buzz word "membership". But I would change "container" to "sequence" because the term "container" doesn't appear in chapter 5, "sequence" on the other hand multiple times. My proposal:

"The comparison operators `in` and `not in` are membership tests that determine whether a value is in (or not in) a sequence."
msg409807 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2022-01-05 21:58
Container is correct.  Containers are defined as being anything that supports the "in" and "not in" operators.  That includes sequences (str, list, tuple, bytes, bytearray), mappings (dict, ChainMap, defaultdict), and sets (frozenset and set).

It doesn't matter that the word container comes up later.  At this point in the tutorial we tend to have a number of forward or references.  Our tutorial is more a guided walkthrough with examples rather than a series of sequential definitions.
msg409836 - (view) Author: Jan (realjanpaulus) Date: 2022-01-06 12:37
Sounds reasonable.
msg410181 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2022-01-10 02:02
New changeset d24cd49acb25c36db31893b84d0ca4fe2f373b94 by Raymond Hettinger in branch 'main':
bpo-46270: Describe the `in` and `not in` operators as membership tests. (GH-30504)
https://github.com/python/cpython/commit/d24cd49acb25c36db31893b84d0ca4fe2f373b94
msg410182 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2022-01-10 02:32
New changeset 2e6798f35260ff90129861ef1f289ac40c0396c2 by Miss Islington (bot) in branch '3.10':
bpo-46270: Describe the `in` and `not in` operators as membership tests. (GH-30504) (GH-30509)
https://github.com/python/cpython/commit/2e6798f35260ff90129861ef1f289ac40c0396c2
History
Date User Action Args
2022-04-11 14:59:54adminsetgithub: 90428
2022-01-10 02:32:01rhettingersetmessages: + msg410182
2022-01-10 02:03:13rhettingersetstatus: open -> closed
stage: patch review -> resolved
2022-01-10 02:02:28miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request28713
2022-01-10 02:02:14rhettingersetmessages: + msg410181
2022-01-09 17:03:17rhettingersetkeywords: + patch
stage: patch review
pull_requests: + pull_request28709
2022-01-06 12:37:05realjanpaulussetresolution: works for me -> fixed
messages: + msg409836
2022-01-05 21:58:37rhettingersetmessages: + msg409807
2022-01-05 21:16:57realjanpaulussetresolution: works for me
messages: + msg409806
2022-01-05 19:14:42rhettingersetmessages: + msg409799
2022-01-05 18:31:17rhettingersetassignee: docs@python -> rhettinger

nosy: + rhettinger
2022-01-05 16:11:18realjanpauluscreate