举例讲解Python中的身份运算符的使用方法
更新时间:2015年10月13日 15:47:05 投稿:goldensun
这篇文章主要介绍了举例讲解Python中的身份运算符的使用方法,是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 selenium的安装和下载谷歌浏览器镜像驱动
Selenium是一个用于web自动化测试的框架,在使用Ajax请求数据的页面中,会出现 sign ,token等密钥,借助使用Selenium框架来实现数据爬取很不错,本文给大家介绍Python selenium的安装和下载谷歌浏览器镜像驱动,需要的朋友可以参考下2022-11-11详细解读Python的web.py框架下的application.py模块
这篇文章主要介绍了Python的web.py框架下的application.py模块,作者深入分析了web.py的源码,需要的朋友可以参考下2015-05-05
最新评论