Python 学习笔记 - 4.if 表达式
时间:2010-12-16 来源:sun5411
方式1
>>>>>> 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
>>>>>> 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' 转载自:http://www.xwy2.com/article.asp?id=108
相关阅读 更多 +