callable() 函数用于检查一个对象是否是可调用的。如果返回True,object仍然可能调用失败;但如果返回False,调用对象ojbect绝对不会成功。

对于函数, 方法, lambda 函式, 类, 以及实现了 __call__ 方法的类实例, 它都返回 True。


def
test(func): # 判断func如果是函数,就执行他,如果不是函数,直接返回 # 判断func是否可调用,如果可以调用,就是true if callable(func): ret = func else: ret = func return ret # print(test(123)) def test2(): return '111' print(test(test2()))

 

相关文章:

  • 2022-01-16
  • 2022-12-23
  • 2022-12-23
  • 2021-08-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-26
猜你喜欢
  • 2022-02-15
  • 2021-10-10
  • 2022-12-23
  • 2022-12-23
  • 2021-09-26
  • 2022-01-24
  • 2022-12-23
相关资源
相似解决方案