isinstance
calls PYL-R1701170def is_simple_callable(obj):
171 """True if obj is a function ()"""
172 return (
173 inspect.isfunction(obj)174 or inspect.ismethod(obj)
175 or isinstance(obj, _builtin_func_type)
176 or isinstance(obj, _builtin_meth_type)
You can pass a tuple of types you want to check as the second argument to isinstance
.
If the object matches with any of the types, it will return True
else False
.
It is therefore recommended to merge multiple consecutive isinstance
calls into one. It is clearer and improves readability.
# Instead of
if isinstance(i, int) or isinstance(i, float):
print('A number')
# Do this
if isinstance(i, (int, float)):
print('A number')