I have a function in Python as
def myfunc(a, b=None, c=None):
my code here
Is there a way to ensure that if the user passes the value of the parameter b
it is necessary to pass the parameter c
to myfunc
?
I have a function in Python as
def myfunc(a, b=None, c=None):
my code here
Is there a way to ensure that if the user passes the value of the parameter b
it is necessary to pass the parameter c
to myfunc
?
You can write a simple if
condition in your function. See the code below:
def myfunc(a, b=None, c=None):
if c is not None and b is None:
raise ValueError("Value of b must be passed if value of c is passed")
your code here
Not in any built in way. Check it yourself:
def myfunc(a, b=None, c=None):
if b is not None and c is None:
raise ValueError("Invalid arguments")
# ...