0
Help us understand the problem. What are the problem?

posted at

updated at

Python: コール可能なオブジェクト(関数とか)かチェックする


def f():
    pass


async def af():
    pass


class C:
    @staticmethod
    def s():
        pass

    @classmethod
    def c(cls):
        pass

    def i(self):
        pass


if __name__ == "__main__":
    print(callable("x")) # False
    print(callable(None)) # False
    print(callable(lambda x: x + 1)) # True
    print(callable(f)) # True
    print(callable(af)) # True
    print(callable(C.s)) # True
    print(callable(C.c)) # True
    print(callable(C.__init__)) # True
    print(callable(C().i)) # True
    print(callable(C.i)) # True

Register as a new user and use Qiita more conveniently

  1. You can follow users and tags
  2. you can stock useful information
  3. You can make editorial suggestions for articles
What you can do with signing up
0
Help us understand the problem. What are the problem?