[Tutor] Boolean operations

Anthony Casey AMCasey at xtra.co.nz
Wed Sep 2 12:30:35 CEST 2009


Hello, tutors.

I'm someone who used to programme as a hobby and who is trying to get back
into it via Python. I'm reading Programming in Python 3 by Summerfield
(excellent book).

I read something unusual about Boolean operations in Python:

>>> five = 5
>>> two = 2
>>> zero = 0
>>> five and two
2

I understand what it's doing here: returning the operand. But what is the
practical application of that? How might I use that function? (Short-sighted
imagination, I realise.)

(I know how binary Booleans work etc., so this is a bit of a change of
outlook.)

Please pardon me if this is a silly or inane question.

Regards,
Anthony



More information about the Tutor mailing list