I have a piece of code that defines a function that takes a function as an argument, like so:
def stuff(n, f):
f(n)
Now, I want to provide some default value of f that does nothing. So I figured I'd use pass, like so:
def stuff(n, f = None):
if(f is None):
f = pass
f(n)
But this does not compile. How should I be doing this?
The pass
is a keyword for the interpreter, a place holder for otherwise nothing. It's not an object that you can assign. You can use a no-op lambda.
f = lambda x: None
Why not simply this ?
def stuff(n, f=None):
if f is None:
return
return f(n)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With