How to check that variable is a lambda function

前端 未结 2 1286
感情败类
感情败类 2021-01-17 11:27

I\'m working on a project, which contains several modules. Simplifying the problem, there is some variable x. Sometimes it may be int or float or list. But it may be a lambd

2条回答
  •  长发绾君心
    2021-01-17 11:45

    If you prefer the typing module, use Callable:

    In [1]: from typing import Callable
    In [2]: isinstance(lambda: None, Callable)
    Out[2]: True
    

提交回复
热议问题