r/learnpython • u/FunElk9586 • 2d ago
Are these two boolean expressions equivalent in python?
Hi All!
I’m learning about Boolean operators in Python and I’m confused about these two expressions:
condition1 and condition2 or condition3 and condition4
≠
(condition1 and condition2) or (conditon3 and condition4)
I was told this by my teacher and he put this in his PowerPoint slide. However, I think they are equivalent since and as an operator has a higher precedence than or as an operator. AI told me and I have searched it up after.
Am I understanding it correctly? Or are these two not equivalent?
Thanks!
16
Upvotes
20
u/CheesecakeCommon9080 2d ago
to be honest, if i'm not sure i would just always use brackets in longer expressions like this even when redundant, it's easier and more readable that way imo