zoukankan      html  css  js  c++  java
  • python bool值要注意的一些地方

    1、像(),[],{}这三个是可以通过bool(()),bool([]),bool({})转化为bool值的;且它们转化后的结果为False。但是这三个值它本身并不等于False、切记不可以与False

    直接进行比较。

    #!/usr/bin/python
    #!coding:utf-8
    import sys
    
    if __name__ =="__main__":
        falseList=[0,False,'',(),[],{}]
        print("the list is :[[0,False,'',(),[],{}]")
    
        print('--------------------------------------------section 001')
        for ix in range(len(falseList)):
            print('the id of item {0} the id when it convert to bool  {1}'.format(id(falseList[ix]),id(bool(falseList[ix]))))
        print('--------------------------------------------section 002')
        print("0==False ?     {0}".format(0==False))
        print("False==False ? {0}".format(0==False))
        print('()==False ?    {0}'.format(() == False))
        print('[]==Flase ?    {0}'.format([]==False))
        print('{{}}==Flase ?    {0}'.format({}==False))

  • 相关阅读:
    Python 知识要点:函数
    软件测试
    软件测试
    软件测试
    SpringBoot框架
    Redis存储系统
    Linux系统
    maven
    shiro安全框架
    Mybatis框架
  • 原文地址:https://www.cnblogs.com/JiangLe/p/5101642.html
Copyright © 2011-2022 走看看