Ternary Operator in Python

Ron_Adam radam2 at tampabay.rr.com
Fri Apr 1 12:47:30 EST 2005


On Fri, 1 Apr 2005 08:24:42 +0100 (BST), praba kar
<prabapython at yahoo.co.in> wrote:

>Dear All,
>    I am new to Python.  I want to know how to
>work with ternary operator in Python.  I cannot
>find any ternary operator in Python.  So Kindly
>clear my doubt regarding this
>
>
>		
>__________________________________ 
>Yahoo! Messenger 
>Show us what our next emoticon should look like. Join the fun. 
>http://www.advision.webevents.yahoo.com/emoticontest


I've used boolean opperations to do it.

	result = (v == value) * first + (v != value) * second

Same as:

	if v == value: result = first else: result = second


Ron




More information about the Python-list mailing list