I know that in python we can use __eq__
method to check equality and __iter__
when using in keyword. Is there any method for is keyword?
Asked
Active
Viewed 138 times
0
-
why are you wanting to override the "is" keyword? Checking if two memory addresses are the same leaves little room for addition. – GranolaGuy Dec 12 '18 at 14:57
-
[You cannot change the implementation of the `is` keyword.](https://stackoverflow.com/a/2987999/10269808) – GranolaGuy Dec 12 '18 at 14:59
-
`is` is the identity operator, IOW it checks if two variables point to the same object. I fail to see how this could be overridden ;-) – bruno desthuilliers Dec 12 '18 at 14:59
-
I am not asking to override it. as @GranolaGuy guy pointed out. I want to know if there is any magic method for is. like if I say. if a is b: in this code. lets assume a and b are instances of some class. now for similar scenarios python has magic functions. but I couldnt find anything for is, Wondering if there is any. – Kireeti K Dec 12 '18 at 15:02
-
`is` does not check if two things are an instance of the same class. `isinstance()` can do that. `is` checks if two things are the _same_ thing. There is not a magic method for `is` like .__is__() – GranolaGuy Dec 12 '18 at 15:06
-
That was just an example, Anyway isinstance can only say if something is an instance of a class. not their ids are the same. This can be a very lame question as i can just do id(a) == id(b). but Just wondering if there is any magic method for it. – Kireeti K Dec 12 '18 at 15:07