# -*- coding: utf-8 -*-
import types
def is_func(fn):
return type(fn) == types.FunctionType or type(fn) == types.BuiltinFunctionType or type(fn) == types.LambdaType \
or type(fn) == types.GeneratorType
print(is_func(abs), is_func(is_func), is_func(lambda x: x**2))
>>> callable(abs) True
Sign in to make a reply
岁益寒
# -*- coding: utf-8 -*-
import types
def is_func(fn):
return type(fn) == types.FunctionType or type(fn) == types.BuiltinFunctionType or type(fn) == types.LambdaType \
or type(fn) == types.GeneratorType
print(is_func(abs), is_func(is_func), is_func(lambda x: x**2))