Negative form of isinstance() in Python
Just use not
. isinstance
just returns a bool
, which you can not
like any other.
That would seem strange, but:
if not isinstance(...): ...
The isinstance
function returns a boolean value. That means that you can negate it (or make any other logical operations like or
or and
).
Example:
>>> a="str">>> isinstance(a, str)True>>> not isinstance(a, str)False
Just use not
, e.g.,
if not isinstance(someVariable, str): ....
You are simply negating the "truth value" (ie Boolean) that isinstance is returning.