[PYTHON] Set method add remove clear

1


s = {1, 2, 3, 4, 5}
s.add(6)
print(s)

Execution result of 1


{1, 2, 3, 4, 5, 6}

2


s = {1, 2, 3, 4, 5}
s.remove(5)
print(s)

Execution result of 2


{1, 2, 3, 4}

3


s = {1, 2, 3, 4, 5}
s.clear()
print(s)

Execution result of 3


set()

To distinguish it from the empty dictionary {} The empty set is represented by set ().

Recommended Posts

Set method add remove clear
Django / Related objects (add, create, remove, clear, set) Summary
SVM optimization by active set method