Hi Alexandre, nice intro to callable.
callable
Python definitely leans on EAFP over LBYL as you know :)
EAFP
A tip: there's an easier way to check if something is a callable that requires zero lines of custom code. The builtin callable() function.
>>> def foo(*args): ... pass ... >>> bar = lambda *args: 0 >>> class Foo: ... def __call__(self, *args): ... print("hello world!") ... >>> callable(foo), callable(bar), callable(Foo), callable(Foo()), callable(3) (True, True, True, True, False)
hope this helps! :-)
Hi! Thanks for the tip, I had forgotten that this existed :/
I'll add that :)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi Alexandre, nice intro to
callable
.Python definitely leans on
EAFP
over LBYL as you know :)A tip: there's an easier way to check if something is a callable that requires zero lines of custom code. The builtin callable() function.
hope this helps! :-)
Hi!
Thanks for the tip, I had forgotten that this existed :/
I'll add that :)