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))

  • 相关阅读:
    基础DP(初级版)
    UVA-816.Abbott's Tevenge (BFS + 打印路径)
    1044: 数圈
    1049: 打牌
    1047: 小A的计算器
    1046: 最小的K个数
    1045: 愚人节的礼物
    1044: 数圈
    1043: 绩点计算
    1042: 小丑排序
  • 原文地址:https://www.cnblogs.com/JiangLe/p/5101642.html
Copyright © 2011-2022 走看看