How set keys are immutable

how set keys are immutable

1 Like

@dk89990

A set is mutable, i.e., we can remove or add elements to it. Set in python is similar to mathematical sets, and operations like intersection, union, symmetric difference, and more can be applied.

It is a collection that is written with curly brackets and is both unindexed and unordered.

Items of a set in python are immutable (unchangeable), do not duplicate values, and unordered. Thus, items in a set do not appear in a stipulated manner, i.e., they can appear in a different order every time it is used. Due to this, set items cannot be referred to by key or index.

After a set is created, its items cannot be changed. However, new items can be added. As we mentioned, all set items need to be unique because duplicates are not allowed. Items in a set can be of any data type.

1 Like

Sets are unordered, they do not have keys or indices assoaciated with them, thus you cannot change values in a set ,although you can add or update values in a set using add() and update() method

1 Like