Meetod remove
Meetod remove eemaldab elemente
hulgast. Kui elementi hulgas ei ole,
tagastatakse viga. Meetodi parameetris
anname elemendi, mille soovime eemaldada.
Süntaks
pythonhulk.remove(mida eemaldame)
Näide
Eemaldame oma hulgast elemendi
'a':
pythonst = {'a', 'b', 'c'}
st.remove('a')
print(st)
Koodi täitmise tulemus:
python{'b', 'c'}
Näide
Nüüd proovime eemaldada elementi, mida hulgas pole:
pythonst = {'a', 'b', 'c'}
st.remove('e')
print(st)
Pärast koodi täitmist saame vea:
errorKeyError: 'e'