[Tutor] Coding

Alan Gauld alan.gauld at btinternet.com
Mon Dec 8 09:17:54 CET 2014

On 08/12/14 02:24, Steven D'Aprano wrote:

>> Python sees it like:
>> if FirstChoice == ('Coke' or 'Pepsi' or 'Water'):
>> So evaluates the bit in parens first which results in a boolean value of
>> True.
> Actually it sees it as:
> if ((FirstChoice == 'Coke') or 'Pepsi' or 'Water'):
> which will always evaluate as True.

Oops, you're right.
Always test...

> # The short way
> if FirstChoice in ('Coke', 'Pepsi', 'Water'):

Which is what I was suggesting so we get to the same end game :-)

Alan G
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:

More information about the Tutor mailing list