Why? Output error msg

Would anyone explain print(d) error message?

def f(x, y):
    return (x**2 + y**2 if x < 0 else
            2*x**2 - y**2 + x*y if 0 <= x < 1 else
            x**2 + 2*y**2 -x + y 
            )
    

a = {f(x == 1, y == 2) for x in range(-10, 10) for y in range(5)}
d = {f(x == 1, y == 2)}
c = {f(x = 1, y = 2)}

print(a)
print(d)
print(c)

Hello,

Change to:

d = {f(x = 1, y = 2)}

Use only one = sign. But then, it would be the same as c. So, what exactly are you trying to obtain or what did you think would be different with respect to c?

This:

a = {f(x == 1, y == 2) for x in range(-10, 10) for y in range(5)}

iterates x from -10 to 9 (inclusive) and y from 0 to 4 (inclusive) and passes whether x is equal to 1 and whether y is equal to 2 to f.

Considering what f does with the values, it’s probably not what’s intended.

This:

d = {f(x == 1, y == 2)}

tries to pass whether x is equal to 1 and whether y is equal to 2 to f, but x and y don’t exist.

This:

c = {f(x = 1, y = 2)}

passes 1 to parameter x and 2 to parameter y of f.