Yes, but it also means hash(b) == hash(x), so equality of the items isn't enough to make them the same.

Answer from Ignacio Vazquez-Abrams on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-check-if-a-set-contains-an-element-in-python
Checking Element Existence in a Python Set - GeeksforGeeks
July 23, 2025 - Python ยท s = {21, 23, '#', "Geeks", ... contains it. operator module is imported and aliased as op and the code then uses op.countOf() method to check if specific elements are present in the set data....
Discussions

Honest Question: Why don't Python strings have a "contains" method?
There is a contain method, it's just the magical method __contains__. Why isn't it called "contain"? Well: implementing the same thing with multiple aliases can cause pollution and confusion over which to use and if there is a difference. Then there is the problem with overriding this method: in operation is not string specific and having a regular method (not magic method) with magic behavior can cause a lot of headache. Or if it was only string specific, then it's still causes confusion: why strings and others need the "in" operation? In short, it would cause headache to implement. More on reddit.com
๐ŸŒ r/Python
35
5
September 6, 2022
Python: See if one set contains another entirely? - Stack Overflow
For "multiset" see python - How to check if all items in a list are there in another list? - Stack Overflow . ... Those are lists, but if you really mean sets you can use the issubset method. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Method to check if an element is in a set and add if not - Ideas - Discussions on Python.org
Consider the case of tracking previously seen values. sets are an ideal data structure for this: seen_items: set seen_items.add(elem) A very common pattern (for me, at least) is to do something special with a value on the first encounter, and then possibly something else every time I see it: ... More on discuss.python.org
๐ŸŒ discuss.python.org
3
November 14, 2025
Contains of HashSet<Integer> in Python - Stack Overflow
In Python, there is a built-in type, set. The major difference from the hashmap in Java is that the Python set is not typed, i.e., it is legal to have a set {'2', 2} in Python. Out of the box, the class set does not have a contains() method implemented. More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
EyeHunts
tutorial.eyehunts.com โ€บ home โ€บ python set contains | example code
Python set contains | Example code - Tutorial - By EyeHunts
September 29, 2022 - If in statement returns True if the specified set contains an element and False otherwise. You have to use โ€œin Keywordโ€ with the if statement. ... Note: Its case sensitive means uppercase and lowercase matter to check the element present ...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ gloss_python_check_if_set_item_exists.asp
Python Check if Item Exists in a Set
Python Functions Python Arguments Python *args / **kwargs Python Scope Python Decorators Python Lambda Python Recursion Python Generators Code Challenge Python Range ... Magic Methods __str__ __repr__ __eq__ __add__ __len__ __lt__ __contains__ __call__ Code Challenge Python Inheritance
๐ŸŒ
PyTutorial
pytutorial.com โ€บ python-set-contains-check-item-membership
PyTutorial | Python Set Contains: Check Item Membership
March 19, 2026 - Learn how to check if an item exists in a Python set using the 'in' keyword and the .__contains__() method for efficient membership testing.
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python โ€บ sets โ€บ .issuperset()
Python | Sets | .issuperset() | Codecademy
May 30, 2024 - In Python, the .issuperset() method is used to determine if the original set contains all elements of the specified set.
๐ŸŒ
Data Science Parichay
datascienceparichay.com โ€บ home โ€บ blog โ€บ check if a set contains an element in python
Check If a Set Contains an Element in Python - Data Science Parichay
January 11, 2022 - You can use the membership operator in to check if a set contains an element or not in Python. It returns True if the element is in the set.
Find elsewhere
๐ŸŒ
Reddit
reddit.com โ€บ r/python โ€บ honest question: why don't python strings have a "contains" method?
r/Python on Reddit: Honest Question: Why don't Python strings have a "contains" method?
September 6, 2022 -

I know there is the in keyword which does the job and does it well, but it's a question of consistency. Isn't one of those python zens all about consistency?

When I can do str.startswith('Foo') and also str.endswith('Foo'), then str.contains('Foo') should be quite obvious and intuitive isn't it? Instead of that, I have to do this:

if 'Foo' in str:
    do_something()

While this does the job and does it great, the contains() method is more practical and intuitive, isn't it? And it's not that the core team even has to do a lot of effort for that. We already have str.__contains__('Foo') which works, so all they have to do is to turn it into a proper method!

๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ set โ€บ issubset
Python Set issubset() (With Examples)
Online Python Online JavaScript Online SQL Online Java Online HTML Online C Online C++ Online C# Online PHP Online Swift Online Kotlin Online TypeScript Online Go Online Rust Online Scala Online Dart Online R Online Ruby ... The issubset() method returns True if set A is the subset of B, i.e.
๐ŸŒ
Real Python
realpython.com โ€บ python-sets
Sets in Python โ€“ Real Python
October 22, 2025 - Note that the resulting sets contain only one instance of "dog" and "cat". The rest of the elements are also in the result. Itโ€™s important to mention that the union operation is commutative, meaning the order of the operands doesnโ€™t affect the outcome. The .union() method works similarly.
๐ŸŒ
Python.org
discuss.python.org โ€บ ideas
Method to check if an element is in a set and add if not - Ideas - Discussions on Python.org
November 14, 2025 - Consider the case of tracking previously seen values. sets are an ideal data structure for this: seen_items: set seen_items.add(elem) A very common pattern (for me, at least) is to do something special with a value on the first encounter, and then possibly something else every time I see it: if elem not in seen_items: seen_items.add(elem) first_encounter(elem) every_encounter(elem) It feels to me that there should be a way to add and return an indicator of whether the value was alr...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_ref_set.asp
Python Set Methods
Python has a set of built-in methods that you can use on sets.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ set
Python Set (With Examples)
Here, we can see there are no duplicate items in the set as a set cannot contain duplicates. Sets are mutable. However, since they are unordered, indexing has no meaning. We cannot access or change an element of a set using indexing or slicing. The set data type does not support it. In Python, we use the add() method to add an item to a set.
๐ŸŒ
Pierian Training
pieriantraining.com โ€บ home โ€บ python __contains__: a comprehensive guide
Python __contains__: A Comprehensive Guide - Pierian Training
May 23, 2023 - These are just a few examples of how to use the โ€œ__contains__โ€ method in Python. This method can be used with any object that supports membership testing, such as sets, tuples, dictionaries, etc.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Multiple element contain check for list, tuple - Python Help - Discussions on Python.org
July 18, 2022 - current scenario - 1) 1 in [1, 2, 3] # or, 1 in (1, 2, 3) โ†’ True but, if one wants to check whether more than one element is in a list, then this technique does not work for a set, there is issubset method, that is, ({1, 2}).issubset({1, 2, 3}) โ†’ True one way to get multiple element contain check is through all keyword, that is, all(i in [1, 2, 3] for i in [1, 2]) โ†’ True expected scenario - there is a method for list, tuple, that works like, ([1, 2]).elements_in([1, 2, 3...
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ set
Python Sets Explained: Efficient Lookups
However, sets cannot contain unhashable types like lists. If you're new to the syntax, exploring a Python tutorial on data structures like sets can help clarify these concepts. You can add an element to a set using the add() method, passing a parameter as an argument.