Aufwind Aufwind - 1 year ago 82
Python Question

Are there sideeffects in python using `if a == b == c: pass;`?

if a == b == c:
# do something

Let's assume
a, b, c
are string variables. Are there any possible side effects if I use the snippet above to execute
# do something
if and only if all three strings are equal?

I am asking because I have to check three variables against each other and I get many cases:

if a == b == c:
# do something
elif a == b != c:
# do something
elif a != b == c.
# do something

Perhaps there is a better way to code this?

Answer Source

There should be no side effects until you use it in a such way.

But take care about things like:

if (a == b) == c:

since it will break chaining and you will be comparing True or False and c value).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download