Python 用科学的方法判断函数/方法

from types import MethodType,FunctionType
def check(arg):
    """
    检查arg是方法还是函数?
    :param arg:
    :return:
    """
    # if isinstance(arg,MethodType):
    #     print('arg是一个方法')
    # elif isinstance(arg,FunctionType):
    #     print('arg是一个函数')
    # else:
    #     print('不知道是什么')

    if type(arg)== MethodType:
        print('arg是一个方法')
    elif type(arg) == FunctionType:
        print('arg是一个函数')
    else:
        print('不知道是什么')
原文地址:https://www.cnblogs.com/fengchong/p/9562928.html