Tertiary Operation
Steven Bethard
steven.bethard at gmail.com
Tue Oct 17 11:12:13 EDT 2006
abcd wrote:
> x = None
> result = (x is None and "" or str(x))
> print result, type(result)
>
> ---------------
> OUTPUT
> ---------------
> None <type 'str'>
>
>
[snip]
> ...what's wrong with the first operation I did with x?
You weren't using Python 2.5:
Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> x = None
>>> '' if x is None else str(x)
''
>>>
Time to upgrade. ;-)
Steve
More information about the Python-list
mailing list