Does 'and' short circuit?

noahspurrier at my-deja.com noahspurrier at my-deja.com
Sun Jan 14 16:40:52 EST 2001


Does the 'and' statement short-circuit?
For example are the following statements safe?

    x={'notfoo':1}
    if x.has_key('foo') and x.get('foo') == 1:
        print 'bar'

It seems to work under the interpreter, but I
have not been able to find a confirmation to this
in the online documentation or tutorial.

Thanks,
Noah


Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list