Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2109693
  • 博文数量: 333
  • 博客积分: 10161
  • 博客等级: 上将
  • 技术积分: 5238
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-19 08:59
文章分类

全部博文(333)

文章存档

2017年(10)

2014年(2)

2013年(57)

2012年(64)

2011年(76)

2010年(84)

2009年(3)

2008年(37)

分类: Python/Ruby

2010-12-16 13:55:15

方式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' 转载自:
阅读(1056) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~