Python reference

Python set methods

Unique items and set maths: add, discard, union, intersection, difference and more.

A set holds each value only once and has no order. Set methods add and remove items and combine sets the way you did in school maths: union (everything), intersection (only what both have) and difference (what one has and the other does not).

All 13 set methods

Spotted a mistake on this page? Tell us