在Python中怎么表达True


为False的几种情况

  • 0为False,其他所有数值皆为True
  • 空串("")为False,其他所有字符串皆为True
  • 空list([])为False,其他所有list皆为True
  • 空tuple(())为False,其他所有tuple皆为True
  • 空dict({})为False,其他所有dcit皆为True

杜绝的几种写法

1
2
3
4
5
if  i = = 0 :
if  str = = “”:
if  list  = =  None :
if  set  is  None :
if  dict  = =  None :

优雅写法

对应上面的例子

1
2
3
4
5
if  not  i:
if  not  str :
if  not  list :
if  not  set :
if  not  dicte:




本文转自jihite博客园博客,原文链接:http://www.cnblogs.com/kaituorensheng/p/4660527.html,如需转载请自行联系原作者


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值