Python for Everybody - Conditional Execution

I am sorry, I am still confusing about the difference in this 4 answer, I think all the same answer for me, also the question is x = 0 but all the multiple choice said 0 == x. Isn’t that backwards??

You may copy the 4 codes to notebook cells, then execute and see what happens. The indentation makes all the difference.

x = 0 and x == 0 are not the same thing

https://stackoverflow.com/questions/33001677/the-differences-between-the-operator-and

if x == 0 and if 0 == x are basically equivalent. “If this equals that” or “if that equals this” you are just checking if two things are equal.

While that’s technically true, if x == 0 does seems a bit more clear and straightforward. I couldn’t find anything official about this in PEP 8 and I’m sure it’s rare to see something like if 0 == x. It seems like the kind of thing that would only appear on a test…

@SzeYeung1 is right, type these into a Python interpreter and see what it does, that’s the best way to learn.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.