举例讲解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 相关文章推荐
详解Python中的__init__和__new__
Mar 12 Python
详解Python中 __get__和__getattr__和__getattribute__的区别
Jun 16 Python
利用python程序生成word和PDF文档的方法
Feb 14 Python
Python正则表达式分组概念与用法详解
Jun 24 Python
Python基于辗转相除法求解最大公约数的方法示例
Apr 04 Python
如何利用python查找电脑文件
Apr 27 Python
基于python 微信小程序之获取已存在模板消息列表
Aug 05 Python
python orm 框架中sqlalchemy用法实例详解
Feb 02 Python
python实现打砖块游戏
Feb 25 Python
Python中bisect的用法及示例详解
Jul 20 Python
Python Opencv轮廓常用操作代码实例解析
Sep 01 Python
python中tkinter复选框使用操作
Nov 11 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 出现乱码和Sessions验证问题的解决方法!
2008/12/06 PHP
PHP 替换模板变量实现步骤
2009/08/24 PHP
php购物车实现方法
2015/01/03 PHP
利用PHP如何统计Nginx日志的User Agent数据
2019/03/06 PHP
一段好玩的JavaScript代码
2006/12/01 Javascript
JS网络游戏-(模拟城市webgame)提供的一些例子下载
2007/10/14 Javascript
加载jQuery后$冲突的解决办法
2010/07/09 Javascript
NodeJs基本语法和类型
2015/02/13 NodeJs
js中for in语句的用法讲解
2015/04/24 Javascript
JS实现网页标题栏显示当前时间和日期的完整代码
2015/11/02 Javascript
利用jquery制作滚动到指定位置触发动画
2016/03/26 Javascript
jQuery表单对象属性过滤选择器实例详解
2016/09/13 Javascript
jQuery基于ajax实现页面加载后检查用户登录状态的方法
2017/02/10 Javascript
原生js实现轮播图
2017/02/27 Javascript
vue router 跳转后回到顶部的实例
2018/08/31 Javascript
JavaScript惰性求值的一种实现方法示例
2019/01/11 Javascript
微信小程序scroll-view实现滚动到锚点左侧导航栏点餐功能(点击种类,滚动到锚点)
2020/06/11 Javascript
[44:33]EG vs Liquid 2018国际邀请赛小组赛BO2 第二场 8.18
2018/08/19 DOTA
Python编写生成验证码的脚本的教程
2015/05/04 Python
Python及PyCharm下载与安装教程
2017/11/18 Python
python利用pandas将excel文件转换为txt文件的方法
2018/10/23 Python
如何利用Anaconda配置简单的Python环境
2019/06/24 Python
Python 计算任意两向量之间的夹角方法
2019/07/05 Python
Python的collections模块真的很好用
2021/03/01 Python
Sofft鞋官网:世界知名鞋类品牌
2017/03/28 全球购物
The Kooples美国官方网站:为情侣提供的法国当代时尚品牌
2019/01/03 全球购物
巴西备受欢迎的服装和生活方式品牌:FARM Rio
2020/02/04 全球购物
最新的大学生找工作自我评价
2013/09/29 职场文书
邮政员工辞职信
2014/01/16 职场文书
运动会广播稿400字
2014/01/25 职场文书
2014年银行员工工作总结
2014/11/12 职场文书
2014七年级班主任工作总结
2014/12/05 职场文书
SQLServer2008提示评估期已过解决方案
2021/04/12 SQL Server
CSS3 制作的图片滚动效果
2021/04/14 HTML / CSS
vue完美实现el-table列宽自适应
2021/05/08 Vue.js
关于html选择框创建占位符的问题
2021/06/09 HTML / CSS