how to use magic methods (delitem and setitem) in python? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

how to use magic methods (delitem and setitem) in python?

I don't know how they are used, one is supposed to clear values ā€‹ā€‹but I don't know how to activate them

25th Feb 2022, 2:33 PM
Pablo Arturo Jimenez De La Cruz
Pablo Arturo Jimenez De La Cruz - avatar
2 Respostas
+ 6
__setitem__ and __delitem__ implementation or implement those methods like e.g. def __setitem__(self, key, value): """ :raise: Always. :raises: TypeError """ self.data_set[key] = value # Raise from tuple. def __delitem__(self, key): """ :raise: Always. :raises: TypeError """ raise TypeError("Item deletion is unsupported")
26th Feb 2022, 2:34 PM
Vaibhav
Vaibhav - avatar
+ 5
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2470/?ref=app If you need help, link your ACTUAL CODE and explain what exactly you want to do.
25th Feb 2022, 3:29 PM
Lisa
Lisa - avatar