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()
python 的None 探究的更多相关文章
- python深浅copy探究
引入 在python程序中,如果我们操作一个变量的值去做运算,而又想在下次调用时,仍使用原来的变量的值去做运算,那么我们我们就需要将这个变量去做备份,这就是本文所要探究的问题. 开始 变量-对象-引用 ...
- Python装饰器探究——装饰器参数
Table of Contents 1. 探究装饰器参数 1.1. 编写传参的装饰器 1.2. 理解传参的装饰器 1.3. 传参和不传参的兼容 2. 参考资料 探究装饰器参数 编写传参的装饰器 通常我 ...
- python strip() 函数探究
strip()方法语法:str.strip([chars]); 声明:str为字符串,rm为要删除的字符序列 str.strip(rm) 删除字符串中开头.结尾处,位于rm删除序列的字符 eg1: # ...
- Python——flask漏洞探究
python的用途是真的多,就连网站也能做,这个有点像Java的Servlet flask基础 hello world 我们先从基础的开始,在网页上打出hello world,python代码如下: ...
- python装饰器探究与参数的领取
首先上原文, 现在,假设我们要增强now()函数的功能,比如,在函数调用前后自动打印日志,但又不希望修改now()函数的定义,这种在代码运行期间动态增加功能的方式,称之为"装饰器" ...
- Python的设计哲学探究
在Python shell中输入import this就会在屏幕上打印出来Python的设计哲学,如下: In [25]: import this The Zen of Python, by Tim ...
- Python下探究随机数的产生原理和算法
资源下载 #本文PDF版下载 Python下探究随机数的产生原理和算法(或者单击我博客园右上角的github小标,找到lab102的W7目录下即可) #本文代码下载 几种随机数算法集合(和下文出现过的 ...
- Python中list的复制及深拷贝与浅拷贝探究
在Python中,经常要对一个list进行复制.对于复制,自然的就有深拷贝与浅拷贝问题.深拷贝与浅拷贝的区别在于,当从原本的list复制出新的list之后,修改其中的任意一个是否会对另一个造成影响,即 ...
- [转帖]虚拟内存探究 -- 第二篇:Python 字节
虚拟内存探究 -- 第二篇:Python 字节 http://blog.coderhuo.tech/2017/10/15/Virtual_Memory_python_bytes/ 是真看不懂哦 ...
随机推荐
- SQLServer2008开启远程连接
1.查看sqlserver brower协议是否启动 2.对象资源管理器 右键属性->选择-> 方面->服务器配置->Remoteaccess ->True 3.对象资源 ...
- react-router4.0的使用
近来很忙,学了一波react,特来记一笔,分享下react-router的使用方式 第一步引入内部组件 import {Route,BrowserRouter as Router,Switch,Lin ...
- led的驱动及测试程序
一.驱动源码 #include <linux/module.h> #include <linux/kernel.h> #include <linux/fs.h> # ...
- 禁止HTML页面缓存
head标签里增加: <meta http-equiv="X-UA-Compatible" content="IE=8"> <meta htt ...
- C/C++基础----变量和基本类型
变量和基本类型 不同平台下基本类型的字节数 类型 16位平台 32位平台 64位平台 char 1 1 1 short 2 2 2 int 2 4 4 long 4 4 8 long long / 8 ...
- SpringBoot中实现依赖注入功能
本文转载自:https://blog.csdn.net/linzhiqiang0316/article/details/52639888 今天给大家介绍一下SpringBoot中是如何实现依赖注入的功 ...
- 【Oracle学习笔记-1】Win7下安装Oracle 10g
源程序获取 从Oracle的官网上下载Oracle 10g: 10203_vista_w2k8_x86_production_db.zip:==>服务器(必须) 10203_vista_w2k8 ...
- 1.环境搭建-mysql+tomcat+myeclipse安装并配置
一.安装mysql数据库并配置 下载地址:https://pan.baidu.com/s/1OJ3ggda7Cthl4GCxWKbTng 密码:sd6b 1.打开安装程序
- R语言学习——欧拉计划(11)Largest product in a grid
Problem 11 In the 20×20 grid below, four numbers along a diagonal line have been marked in red. 08 0 ...
- cookie js案例
//存cokie function setcookie(keys,value,time){ document.cookie=keys+"="+decodeURIComponent( ...