Are Python Sets Mutable?
Answer : >>>> x = set([1, 2, 3]) >>>> y = x >>>> >>>> y |= set([4, 5, 6]) >>>> print x set([1, 2, 3, 4, 5, 6]) >>>> print y set([1, 2, 3, 4, 5, 6]) Sets are unordered. Set elements are unique. Duplicate elements are not allowed. A set itself may be modified, but the elements contained in the set must be of an immutable type. set1 = {1,2,3} set2 = {1,2,[1,2]} --> unhashable type: 'list' # Set elements should be immutable. Conclusion: sets are mutable. Your two questions are different. Are Python sets mutable? Yes: "mutable" means that you can change the object. For example, integers are not mutable: you cannot change the number 1 to mean anything else. You can, however, add elements to a set, which mutates it. Does y = x; y |= {1,2,3} change x ? Yes. The code y = x means "bind the name y to mean the same object that the name x currently represents...