Python equivalent to a C trick

Thomas Krüger thomas.krueger at gmx.net
Tue Aug 10 05:53:53 EDT 2004


Dan wrote:

> Is there a python equivalent of this trick in C?
> 
> Logic_Test ? True_Result : False_Result
> 
> Example:
> printf( "you have %i %s", num_eggs, num_eggs > 1 ? "eggs" : "egg" );

Logic_Test and True_Result or False_Result

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

Thomas



More information about the Python-list mailing list