My experience of confusing boolean expressions was the code:
>>> 1 == 2 in [2, False]
False
which, when parenthesised the two possible ways
>>> (1 == 2) in [2, False]
True
>>> 1 == (2 in [2, False])
True
results in sensible values (although the second one's sensibility is
debatable)
I couldn't f
On Mon, Mar 28, 2011 at 10:06 PM, Michael H. Goldwasser wrote:
>
> To start a new thread, I'm always trying to keep a list of some common
> "gotchas" that beginning students run across when using Python, or
> things that teachers should keep in mind when teaching with the
> language.
Sincere app
Hi,
I agree that the behavior of booleans in Python can sometimes lead to subtle
errors, but I think it's important to stress to students that writing things
like:
if x>y == True:
is _really_ bad style. After pointing that out, I start taking points away for
doing this. Code like this shows t
Hi,
I really like it that python allows me to write
if 10 < x <= b:
...
impossible in many other languages.
But all things come at a cost:
if x > y == True:
I think this is a real gotcha, because it might get you, because you
_know too much_:
>>> if 4:
print True