May be irritating for some but good practice regardless.
Putting the constant left in a conditional means you will never miss an accidental = instead of ==.
Putting the constant left in a conditional means you will never miss an accidental = instead of ==.
That's only useful for dumb languages
>>> a = 5
>>> if a = 3: print 'ok'; else: print 'nok'
File "<stdin>", line 1
if a = 3: print 'ok'; else: print 'nok'
^
SyntaxError: invalid syntax
Python simply does not allow assignments in conditional contexts.The difference between theory and practice is smaller in theory than in practice.
I carefully weighted my words, and I rest my case.
The compilers/interpreters I know that don't do this are PHP and Perl (C/C++ will do it if you use -Wall, which you should be using anyway).
So yeah, you're pretty much right. /snark
Don't be an idiot in the first place and you won't have to do idiotic things to prevent damage from your idiocy.
Good judgement is the result of experience.
Experience is the result of bad judgement. <-- You are here