转载自: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'
posted on 2008-09-04 13:19  sislcb  阅读(721)  评论(0编辑  收藏  举报