[Tutor] If - else Vs OR

Alan Gauld alan.gauld at yahoo.co.uk
Wed Jul 22 18:53:57 EDT 2020


On 22/07/2020 23:42, Alan Gauld via Tutor wrote:

> C/C++ has a similar construct:
> 
> <value> ? <test> : <other value>

Oops, I got that wrong.
Its

<test> ? <true value> : <false value>

But the end result is the same. It's an expression
that returns a single value depending on the result
of a test.

Sorry for any confusion caused.

Also it's worth pointing out that in fact the "values"
returned can themselves be expressions (in both the
C or Python versions) But that's usually a bad idea
since it can result in pretty convoluted code!

-- 
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