[Tutor] Conditional Statement without if statement?
Alan Gauld
alan.gauld at yahoo.co.uk
Tue Feb 8 18:50:18 EST 2022
On 08/02/2022 10:35, Alan Gauld via Tutor wrote:
> The only thing to remember after that is that Python returns
> the actual values from a boolean comparison.
>
> Thus
>
> x = 42 or 66
>
> x will have the value 66
Oops! And that demonstrates why you shouldn't use it
as a conditional statement! :-)
I actually had a much longer answer typed out with
multiple examples from the >>> prompt but then decided
I was overcomplicating things so used this simpler but
untested example. sigh.
--
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