CKTIS / Python
set.discard
Iz množice odstrani navedeni element, če je v njej.
Različica: Python 3.14; repository image, production runtime not attested
Sintaksa
s.discard(element, /)Iz množice odstrani navedeni element, če je v njej.
Manjkajoča vrednost 99 drugače kot pri remove ne sproži KeyError. Po odstranitvi 3 ostane {2}.
Oba klica vrneta None, zato rezultat ne pove, ali se je množica spremenila.
s = {1}
assert s.discard(9) is None and s.discard(1) is None and not s
Primeri
s = {2, 3}
print(s.discard(99))
s.discard(3)
print(sorted(s))
Rezultat
None [2]
Oba klica vrneta None, zato rezultat ne pove, ali se je množica spremenila.