Operations on Sets

The set and frozenset type support a number of common set operations:

OperationDescription
s | tUnion of s and t
s & tIntersection of s and t
s – tSet difference
s ^ tSymmetric difference
len(s)Number of items in the set
max(s)Maximum value
min(s)Minimum value

Get Python: Essential Reference, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.