From what I have researched most operators and methods can be overridden when creating a class in python. By using __add__(self, other) and others for example.
My "problem" (more like I don't quite understand how it is done) is for verifying is something is in my class I have to obviously use __contains__(self, theThing).
Alas I thought this should return a boolean value in the code itself, but from example code I have seen, like this:
def __contains__(self, posORname):
return [node.getId() for node in self.tree if node.getId() == posORname or node.getName() == posORname]
What I am returning is therefore a tuple containing the Id of where said item is.
Could someone explain why this is done instead of returning True or False? And if so, shouldn't it be implicitly possible to get the index of an item in a structure by just using in?
Thanks :D