I have a function in Python as
JavaScript
x
3
1
def myfunc(a, b=None, c=None):
2
my code here
3
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
?
Advertisement
Answer
You can write a simple if
condition in your function. See the code below:
JavaScript
1
5
1
def myfunc(a, b=None, c=None):
2
if c is not None and b is None:
3
raise ValueError("Value of b must be passed if value of c is passed")
4
your code here
5