Tertiary Operation

abcd codecraig at gmail.com
Tue Oct 17 09:30:32 EDT 2006


x = None
result = (x is None and "" or str(x))

print result, type(result)

---------------
OUTPUT
---------------
None <type 'str'>


y = 5
result = (y is 5 and "it's five" or "it's not five")

print result

-------------
OUTPUT
-------------
it's five

...what's wrong with the first operation I did with x?  I was expecting
"result" to be an empty string, not the str value of None.




More information about the Python-list mailing list