Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
Python

Sets in Python

Store unique unordered values and perform union/intersection with sets.

Sets in Python — a practical guide to Python sets with clear examples you can reuse in real projects.

Python Tutorial Series (23/95). Prefer one article? Read the complete Python tutorial.

Short description

Sets automatically remove duplicates and are fast for membership tests.

Set operations

a = {1, 2, 2, 3}
b = {3, 4}
print(a)              # {1, 2, 3}
print(a | b)          # union
print(a & b)          # intersection
print(2 in a)

Leave a reply

Your email address will not be published. Required fields are marked *