<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: No ternary operator in Python</title>
	<atom:link href="http://truefalsemaybe.com/2008/09/no-ternary-operator-in-python/feed/" rel="self" type="application/rss+xml" />
	<link>http://truefalsemaybe.com/2008/09/no-ternary-operator-in-python/</link>
	<description>tom longson's blog on software, design, and user experience</description>
	<lastBuildDate>Tue, 01 Jun 2010 13:09:28 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Dan</title>
		<link>http://truefalsemaybe.com/2008/09/no-ternary-operator-in-python/comment-page-1/#comment-129</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Wed, 10 Sep 2008 20:10:00 +0000</pubDate>
		<guid isPermaLink="false">http://truefalsemaybe.com/?p=40#comment-129</guid>
		<description>yes, python has a ternary.

expr-1 if bool-expr else expr-2

def int_to_float(v):
    return float(v) if isinstance(v, int) else 0.0</description>
		<content:encoded><![CDATA[<p>yes, python has a ternary.</p>
<p>expr-1 if bool-expr else expr-2</p>
<p>def int_to_float(v):<br />
    return float(v) if isinstance(v, int) else 0.0</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Janzert</title>
		<link>http://truefalsemaybe.com/2008/09/no-ternary-operator-in-python/comment-page-1/#comment-128</link>
		<dc:creator>Janzert</dc:creator>
		<pubDate>Wed, 10 Sep 2008 19:28:12 +0000</pubDate>
		<guid isPermaLink="false">http://truefalsemaybe.com/?p=40#comment-128</guid>
		<description>The ternary operator was added in 2.5, the form is:

true_val if condition else false_val

so:

def int_to_float(v):
    return 0.0 if type(v) != int else float(v)

If you need to be compatible with older versions though you are stuck of course. Also as you probably know but just as a note for anyone that happens across this, direct type comparisons as used in the examples above are discouraged since it will break any chance of duck types working.</description>
		<content:encoded><![CDATA[<p>The ternary operator was added in 2.5, the form is:</p>
<p>true_val if condition else false_val</p>
<p>so:</p>
<p>def int_to_float(v):<br />
    return 0.0 if type(v) != int else float(v)</p>
<p>If you need to be compatible with older versions though you are stuck of course. Also as you probably know but just as a note for anyone that happens across this, direct type comparisons as used in the examples above are discouraged since it will break any chance of duck types working.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
