举例讲解Python中的身份运算符的使用方法


Posted in Python onOctober 13, 2015

Python身份运算符
身份运算符用于比较两个对象的存储单元

举例讲解Python中的身份运算符的使用方法

以下实例演示了Python所有身份运算符的操作:

#!/usr/bin/python

a = 20
b = 20

if ( a is b ):
  print "Line 1 - a and b have same identity"
else:
  print "Line 1 - a and b do not have same identity"

if ( id(a) == id(b) ):
  print "Line 2 - a and b have same identity"
else:
  print "Line 2 - a and b do not have same identity"

b = 30
if ( a is b ):
  print "Line 3 - a and b have same identity"
else:
  print "Line 3 - a and b do not have same identity"

if ( a is not b ):
  print "Line 4 - a and b do not have same identity"
else:
  print "Line 4 - a and b have same identity"

以上实例输出结果:

Line 1 - a and b have same identity
Line 2 - a and b have same identity
Line 3 - a and b do not have same identity
Line 4 - a and b do not have same identity
Python 相关文章推荐
Saltstack快速入门简单汇总
Mar 01 Python
python实现快速排序的示例(二分法思想)
Mar 12 Python
对python中的pop函数和append函数详解
May 04 Python
Pycharm保存不能自动同步到远程服务器的解决方法
Jun 27 Python
python获取点击的坐标画图形的方法
Jul 09 Python
将Pytorch模型从CPU转换成GPU的实现方法
Aug 19 Python
pytorch梯度剪裁方式
Feb 04 Python
如何在mac下配置python虚拟环境
Jul 06 Python
Python安装并操作redis实现流程详解
Oct 13 Python
利用Python如何画一颗心、小人发射爱心
Feb 21 Python
详解OpenCV获取高动态范围(HDR)成像
Apr 29 Python
python和anaconda的区别
May 06 Python
Python中的字典与成员运算符初步探究
Oct 13 #Python
详解Python中的元组与逻辑运算符
Oct 13 #Python
如何准确判断请求是搜索引擎爬虫(蜘蛛)发出的请求
Oct 13 #Python
Python语法快速入门指南
Oct 12 #Python
初步认识Python中的列表与位运算符
Oct 12 #Python
Python入门学习之字符串与比较运算符
Oct 12 #Python
各个系统下的Python解释器相关安装方法
Oct 12 #Python
You might like
php基于curl重写file_get_contents函数实例
2016/11/08 PHP
基于swoole实现多人聊天室
2018/06/14 PHP
laravel-admin 实现给grid的列添加行数序号的方法
2019/10/08 PHP
PHP 计算至少是其他数字两倍的最大数的实现代码
2020/05/26 PHP
采用CSS和JS,刚好我最近有个站点要用到下拉菜单!
2006/06/26 Javascript
通过url查找a元素应用案例
2014/04/29 Javascript
javascript中通过arguments参数伪装方法重载
2014/10/08 Javascript
js实现数组转换成json
2015/06/26 Javascript
php结合imgareaselect实现图片裁剪
2015/07/05 Javascript
JavaScript常用本地对象小结
2016/03/28 Javascript
Bootstrap下拉菜单效果实例代码分享
2016/06/30 Javascript
漂亮! js实现颜色渐变效果
2016/08/12 Javascript
前端程序员必须知道的高性能Javascript知识
2016/08/24 Javascript
vue-devtools的安装步骤
2018/04/23 Javascript
Node.js Windows Binary二进制文件安装方法
2019/05/16 Javascript
jquery 时间戳转日期过程详解
2019/10/12 jQuery
Vue触发input选取文件点击事件操作
2020/08/07 Javascript
vue监听滚动事件的方法
2020/12/21 Vue.js
[46:23]OG vs EG 2018国际邀请赛淘汰赛BO3 第一场 8.23
2018/08/24 DOTA
详谈Python3 操作系统与路径 模块(os / os.path / pathlib)
2018/04/26 Python
基于tensorflow加载部分层的方法
2018/07/26 Python
解决python3捕获cx_oracle抛出的异常错误问题
2018/10/18 Python
python 把列表转化为字符串的方法
2018/10/23 Python
Python常用爬虫代码总结方便查询
2019/02/25 Python
python画蝴蝶曲线图的实例
2019/11/21 Python
Python flask框架如何显示图像到web页面
2020/06/03 Python
HTML5 video循环播放多个视频的方法步骤
2020/08/06 HTML / CSS
奥地利网上现代灯具和灯饰店:Lampenwelt.at
2018/01/29 全球购物
俄罗斯童装网上商店:BebaKids
2020/06/06 全球购物
环保专业大学生职业规划设计
2014/01/10 职场文书
新郎父亲婚宴答谢词
2014/01/11 职场文书
党员公开承诺书2015
2015/01/21 职场文书
心理健康教育培训研修感言
2015/11/18 职场文书
2019年大学毕业生个人自我鉴定范文大全
2019/03/21 职场文书
68句权威创业名言
2019/08/26 职场文书
吃通javascript正则表达式
2021/04/21 Javascript