I want to define a function to which the input parameters can be omitted or have a default value.
I have this function:
def nearxy(x,y,x0,y0,z):
d
You can't make function arguments optional in Python, but you can give them default values. So:
def nearxy(x, y, x0=0, y0=0, z=None):
...
That makes x0
and y0
have default values of 0
, and z
have a default value of None
.
Assuming None
makes no sense as an actual value for z
, you can then add logic in the function to do something with z
only if it's not None
.