A certainl part of an if() structure never gets executed.
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sun Jun 16 01:09:52 EDT 2013
On Sat, 15 Jun 2013 18:55:05 -0700, Tim Roberts wrote:
> Nick the Gr33k <support at superhost.gr> wrote:
>>
>>but i'm doing this all day long i just dont comprehend why it works this
>>way. it doesn't make any sense to me.
>
> It's just a rule you'll have to learn. The "and" and "or" operators in
> Python simply do not return a boolean value. The expression "a or b" is
> evaluated as:
> if a is true then return a otherwise return b
I prefer to say that as
"if a is true-ish then return a otherwise return b"
or even
"if a quacks like a true value then return a otherwise return b"
to emphasis that this is a form of duck-typing, and avoid any confusion
with "if a is True".
But otherwise, well said.
--
Steven
More information about the Python-list
mailing list