3 ms·
> 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
by masklinn 16y ago
> 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.
- moe 16y agoDumb is a strong word, young padawan. The difference between theory and practice is smaller in theory than in practice.
- masklinn 16y ago> Dumb is a strong word, young padawan. I carefully weighted my words, and I rest my case.
- 146 16y ago> That's only useful for dumb languages 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