美文网首页
2018-10-09 Python22 if真假

2018-10-09 Python22 if真假

作者: 孟媛的笔记 | 来源:发表于2018-10-09 11:10 被阅读0次

    假:

    In [1]: if "":
       ...:     print("1")
       ...:     
    
    In [2]: if None:
       ...:     print("2")
       ...:     
    
    In [3]: if 0:
       ...:     print("3")
       ...:     
    
    In [4]: if []:
       ...:     print("4")
       ...:     
    
    In [5]: if {}:
       ...:     print("5")
       ...:     
    
    In [6]: if ():
       ...:     print("6")
       ...:     
    

     

    真:

    In [8]: if not False:
       ...:     print("8")
       ...:     
    8
    
    In [9]: if 1:
       ...:     print("9")
       ...:     
    9
    
    In [10]: if -1:
       ....:     print("10")
       ....:     
    10
    
    In [11]: if "a":
       ....:     print("11")
       ....:     
    11
    

    相关文章

      网友评论

          本文标题:2018-10-09 Python22 if真假

          本文链接:https://www.haomeiwen.com/subject/uvdeaftx.html