This might be a basic question because I am still learning Python. But let's suppose I want to do something like this,
def add(a, b):
return a + b
a, b, c, d = 1, 2, 3, 4
sum = add(a, b if b == 2 else c, d)
Basically, I am trying to pass multiple functional args from inside a ternary operator(and I want a similar solution, if possible). This code currently gives the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: add() takes 2 positional arguments but 3 were given
What else have I tried:
add((a, b) if b == 2 else (c, d))add(*(a, b) if b == 2 else *(c, d))