转载自:http://www.xwy2.com/article.asp?id=108
方式1
Code
>>>>>> s = ""
>>>>>> a = s or "not none"
>>>>>> a
'not none'
>>>>>> s = None
>>>>>> a = s or "not none"
>>>>>> a
'not none'
>>>>>> s = "aa"
>>>>>> a = s or "not none"
>>>>>> a
'aa'
方式2
Code
>>>>>> s = None
>>>>>> a = "not null" if s == None else s
>>>>>> a
'not null'
>>>>>> s = "aa"
>>>>>> a = "not null" if s == None else s
>>>>>> a
'aa'