How to refer to types in Python? -
i know how refer types, i.e. str
type('')
, int
type(1)
etc. other types, such type(lambda: none)
?
i know refer type(f) == type(lambda: none)
comparison, but, there other way, except that? (no silly answer such code-golf, use return value lambda, etc.)
edit: found out how utilize accepted answer!
import types function = types.functiontype builtin_function_or_method = types.builtinfunctiontype classobj = types.classtype generator = types.generatortype object = type del types
if want test if value a lambda:
import types foo = lambda: none print(isinstance(foo, types.lambdatype))
see https://docs.python.org/3/library/types.html.
you use isinstance
testing if something, type() == type()
frowned upon.
Comments
Post a Comment