I’m trying to make a function where two variables are in one if
statement. followed by a(n) == True
. It doesn’t work, but here’s what I tried in a better format.
if var1, var2 == True: print("This function is correct") else: print("This function doesn't work")
but it returned this message:
Invalid Syntax
Is there a way to make this function possible?
Advertisement
Answer
Keep in mind that you can take advantage var1
and var2
are booleans, so:
if var1 and var2: # your logic
Alternative, you can use the all
function
if all([var1, var2]): # your logic
Note: you don’t need to check equality for True
in a conditional, the point is to take advantage of that.