...

/

Basic Set Operations

Basic Set Operations

Learn about the basic set operations in Python.

Some basic set operations are given below.

Mutability

Sets are mutable. Their contents can be changed, as shown below.

Press + to interact
s = {'gate', 'fate', 'late'}
s.add('rate') # adds one more element to set s
print(s)

If we want an immutable set, we can use a frozenset.

Press + to interact
s = frozenset({'gate', 'fate', 'late'})
s.add('rate') # error

Other operations

The following are operations that work on lists and tuples. Try these operations on sets in the playground given below:

...