0

this magic-method i dont understand it i prefer to give me example for etch one

__delitem__ __iter__ __contains__ if you give me example code i will be thankful for you

15th Nov 2018, 7:43 AM
Omar Muhammad Nofal
Omar Muhammad Nofal - avatar
2 Respostas
+ 2
They would be implemented for your class only if meaningful... __delitem__ : called when you want custom delete on you object item in form delete obj[item] https://docs.python.org/3/reference/datamodel.html#object.__delitem__ __iter__: called when you want an iterator for iterate on you object https://docs.python.org/3/reference/datamodel.html#object.__iter__ __contains__: called when you want check if an item is contained in your object https://docs.python.org/3/reference/datamodel.html#object.__contains__ I repeat, these have to be implemented ONLY if meaningful and you want custom handling for respective case
15th Nov 2018, 8:57 AM
KrOW
KrOW - avatar
0
what is the function should call it in main programme to call the __delitem__ and __iter__
15th Nov 2018, 3:33 PM
Omar Muhammad Nofal
Omar Muhammad Nofal - avatar