Python equivalent to a C trick

Erik Max Francis max at alcyone.com
Tue Aug 10 12:13:41 CEST 2004


Thomas Krüger wrote:

> Logic_Test and True_Result or False_Result
> 
> Example:
> print (num_eggs > 1) and 'eggs" or "egg"

Be very careful that the "True_Result" in your formulation actually is
itself a Python true value, or this won't work:

	print 'egg' + (numEggs == 1 and '' or 's')

will not work as expected.

-- 
 __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
/  \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
\__/ Melancholy men, of all others, are the most witty.
    -- Aristotle



More information about the Python-list mailing list