首页 > 编程语言 > 详细

[python]Python 中 if not 用法

时间:2020-02-14 16:11:11      阅读:62      评论:0      收藏:0      [点我收藏+]

在python 判断语句中 None, False, 空字符串"", 0, 空列表[], 空字典{}, 空元组()都相当于 False
not None == not False == not ‘‘ == not 0 == not [] == not {} == not ()

 

需要注意的是‘0‘这个进行判断返回的是true

def test(val):
    if not val:
        print not
    else:
        print yes

test(0)
test(None)

test(0)


if not 0:
    print 1111

返回

not
not
yes
1111

 

[python]Python 中 if not 用法

原文:https://www.cnblogs.com/taoshihan/p/12307530.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!