[Tutor] Python Question

Alan Gauld learn2program at gmail.com
Tue Jul 6 04:14:02 EDT 2021


On 06/07/2021 07:33, Peter Otten wrote:
> On 05/07/2021 10:11, Alan Gauld via Tutor wrote:
> if investor != ["conservative" or "moderate" or "aggressive"]:
>> This does not do what you want. 
Let's see:
>  >>> ["conservative" or "moderate" or "aggressive"]
> ['conservative']
>
> So no, the expression
>
> a or b or c
>
> picks the first value that evaluates to True in a boolean context, 

Oops! Good catch, I should have got that.

But it still doesn't do what the OP intended. :-)

-- 

Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list