码迷,mamicode.com
首页 > 其他好文 > 详细

if...not...

时间:2018-11-24 15:40:08      阅读:289      评论:0      收藏:0      [点我收藏+]

标签:写法   判断   col   赋值   div   列表   字符串   pyhon   ...   

  关于pyhon中的None

  None是一个特殊的常量。

  None不是0。

  None不是字符串。

  None和任何其他的数据类型比较永远返回False。

  None有自己的数据类型:None Type。

  你可以将None赋值给任何变量,但是你不能创建其他None Type对象。

  None和False不同。布尔类型只包括两个:True和False,但python中把0,空字符串,空列表,空字典,空元组都和None都看作False,把其他数值和非空字符串都看作True。


 

  if not :一个判断语句,not表示 ‘非‘

if not x:
    do_someting()


x = [1]
if not x:
    print(haha)
else:
    print(heihei)
>>>heihei


x = []
if not x:
    print(haha)
else:
    print(heihei)
>>>haha

  如果x为False(False,None,空字符串,空列表,空字典,空元组,0),执行分支里的语句。这种写法的前提是:必须清楚x等于一个False。

not None == not False == not ‘‘ == not 0 == not [] == not {} == not ()

 

  if not = if x is None

 

if...not...

标签:写法   判断   col   赋值   div   列表   字符串   pyhon   ...   

原文地址:https://www.cnblogs.com/romacle/p/9960646.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!