isfunc#
- isfunc(obj)[source]#
Quickly check if something is a function.
This checks whether or not something is a method (
types.MethodType) or a function (types.FunctionType), which is different to whether or not it is callable (e.g., classes are callable).Note: Python doesn’t have a crystal-clear distinction between things that are and aren’t functions, so there may be some edge cases with this function. For example,
dict.fromkeysis abuiltin_function_or_method, which returns True. So islist().popandlist().remove. Butlist.popandlist.removeare different types, and returnFalse. The full list of types it checks against is:types.FunctionType
types.MethodType
types.BuiltinFunctionType
types.BuiltinMethodType
types.LambdaType
functools.partial
staticmethod
classmethod
Example:
sc.isfunc(list) # Returns False callable(list) # Returns True
New in version 3.2.0.New in version 3.2.3: also checks for partial and lambda functions