Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
is vs in
#2
No way to redefine it that I'm aware of.

Quote:For container types such as list, tuple, set, frozenset, dict, or collections.deque, the expression x in y is equivalent to any(x is e or x == e for e in y).

Given that, I would just redo your test as the same comprehension, just without the equality test.

>>> item = 1
>>> mylist = [True]
>>> item in mylist
True
>>> any(x is item for x in mylist)
False
Skaperen likes this post
Reply


Messages In This Thread
is vs in - by Skaperen - Dec-20-2020, 01:56 AM
RE: is vs in - by bowlofred - Dec-20-2020, 03:00 AM
RE: is vs in - by Skaperen - Dec-20-2020, 05:19 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020