I a have a function with 2 variables set be default to None
def foo(x, y=None, z=None):
...
I want to make sure that if they are passed they both need to be not None.
I did the following:
if y is not None:
assert z is not None
But I wonder if there is a more elegant way of doing this check.
If only 1 of them is None I want to assert while if both of them are it’s ok.
>Solution :
You can do something like this
if (y is None) == (z is None):
# both are None or both are not None
else:
# one of them is None