I was eager to know about the what is the difference between
all and "and"
any and "or"
for example: status1=100,status2=300,status3=400
Which is better to use:
if status1==100 and status2 ==300 and status3 ==400:
or
if all([status1==100,status2==300,status3==400]):
similarly for the any and or condition:
if status1==100 or status2 ==300 or status3==400:
or
if any([status1==100, status2 ==300, status3==400])
which one is more efficent, using the builtin functions or the primitive or and and conditions ?
The keywords and
and or
follow Python's short circuit evaluation rules. Since all
and any
are functions, all arguments would be evaluated. It's possible to get different behaviour if some of the conditions are functions calls.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With