zoukankan      html  css  js  c++  java
  • python 的None 探究

    a = None
    b = None
    print id(a),id(b),id(None)  # 9430224 9430224 9430224 可能在别的环境下运行不是这个数,但是这三个数应该是一样的。
    print a == b == None     # True
    print type(None)
    print "#####  以下均为 False ####"
    print 0 == None
    print 0 is None
    print {} == None
    print {} is None
    print [] == None
    print [] is None
    print "" == None
    print "" is None
    print () == None
    print () is None
    print False is None
    print False == None
    print (not True) is None
    print (not True) == None
    print (not [1,]) == None
    print (not [1,]) is None
    print not [1,]
    print not True
    print "######  以上均为 False ######### "
    print (not None) # True
    print  True is not None   # True
    print [] is not None    # True
    print [1] is not None   # True
    print False is not None   # True
    print None == None  # True
    print None is None   # True
    print (not None)
    

    None 既不是 0,[],{},也不是 " ",它就是一个空值对象。其数据类型为 NoneType,遵循单例模式。它只是自己,也只和自己相等。

    list1 = []
    # list1 = [1]
    
    if list1 is not None:  # 这句话可能想表达的意思是:如果list1 不为空。就怎样怎样。在这里面隐藏着一个错误的认识 [] == None
        print"我不是空的"  #将会打印这句 无论list1 是否真的为空,如此写法都只会打印这句
    else:
        print"我是空的"
    
    if list1 is None:
        print '我不是空的'
    else:
        print '我是空的'  #将会打印这句  无论list1 是否真的为空,如此写法都只会打印这句
    
    
    if list1:
        print"我不是空的" # 如果list1 不为空,将会打印这句。
    else:
        print "我是空的" #将会打印这句
    
    
    
    print id(None)
    def ae(m = None):
        print id(m)
        print m
        if m == None:
            print 'aasd'
    
    ae()
    
  • 相关阅读:
    Convolution1D与Convolution2D区别
    git
    cast函数
    Ubuntu14.04编译WebRTC For Android代码 2014-07-24
    R语言基础-数组和列表
    疯狂的创业运动
    Autodesk 举办的 Revit 2015 二次开发速成( 1.5 天),教室培训, 地点武汉
    注冊(十一)重注冊带有鉴权信息
    ubuntu14.04无法安装Curl
    Bash脚本中的操作符
  • 原文地址:https://www.cnblogs.com/jijizhazha/p/7122139.html
Copyright © 2011-2022 走看看