def func(arg): ''' 判断arg是否可以被调用,如果可以则执行并打印其返回值,否则直接打印结果 :param arg: :return: ''' if callable(arg) == True: print("%s可调用"% arg) res = arg() print(res) else: print("%s不可调用" % arg) def fun1(): # print(123) return 123 a = "this is a" func(fun1) func(a)