Jump to the cheat sheet
Key points
- Unlike lists and tuples, a set is an unordered collection of unique elements.
- A set can be created using the set() constructor. It takes an optional iterable as input.
- Sets with some elements can also be initialized using the curly braces (e.g., {1, 2, 3}).
- However, curly braces cannot be used to create an empty set. Using empty curly braces, i.e., {}, creates a dictionary datatype in Python.
- 'in' operator can be used to check the presence of an element in a set.
- Sets support the mathematical set operations like union, intersection, difference, symmetric difference, etc.
- Sets are mutable, we can add or remove elements from them.
Cheat sheet
Useful resources and references
from Planet Python
via read more
No comments:
Post a Comment