June 2017
Beginner
352 pages
8h 39m
English
To add a single element to a set use the add() method:
>>> k = {81, 108}>>> k{81, 108}>>> k.add(54)>>> k{81, 108, 54}>>> k.add(12)>>> k{81, 108, 54, 12}
Adding an element that already exists has no effect:
>>> k.add(108)
Although neither does it produce an error. Multiple elements can be added in one go from any iterable series, including another set, using the update() method:
>>> k.update([37, 128, 97])>>> k{128, 81, 37, 54, 97, 12, 108}
Read now
Unlock full access