2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

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

Last updated at Posted at 2022-03-22

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
2
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?