Why does the behaviour of the in operator/__contains__ method differ from manual equality checks? [duplicate]
I found out that it is possible to check whether certain Numpy result are of a specific Numpy dtype, by checking whether they occur in a list of dtype-class objects: Python 3.11.14 (main, Oct 21 2025, 18:31:21) [GCC 11.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import numpy as np >>> np.__version__ '2.3.3' >>> np.equal(1,1) in [np.dtypes.BoolDType()] True It seems to indeed perform some check that it is actually the specific dtype: >>> np.equal(1,1) in [np.dtypes.Float32DType()] False I always assumed that the in operator, aka the __contains__ meth
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.