How can I test whether a variable holds a lambda?

This is years past-due, but callable(mylambda) will return True for any callable function or method, lambdas included. hasattr(mylambda, '__call__') does the same thing but is much less elegant.

If you need to know if something is absolutely exclusively a lambda, then I’d use:

callable(mylambda) and mylambda.__name__ == "<lambda>"

(This answer is relevant to Python2.7.5, onwards.)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)