Sets are mutable (can be changed) data types where you can add elements to it. But the elements you want to add must be immutable. Yes, you hear it right. Sets are mutable data type which can allow only immutable elements added to it.
In all the above examples you can see it is not allowing any mutable element(list, dictionary, sets) assigned to it. In fact it won’t even allow set inside a set. So nested sets is not possible due to this principle.
The same is true even when we use add function in sets to add a mutable element. Below are some examples.
So the question is how can I add list of elements to a set which are stored in mutable data type like lists or sets. Is it not possible?
It is possible using update function in sets but will add them as individual elements to the set. In case of lists and sets it add them as individual elements to set whereas for dictionaries it add only keys. Below are examples.