讲解Python中的标识运算符

yipeiwu_com6年前Python基础

 下表列出了所有Python语言支持的标识运算符。

2015514101018679.jpg (589×219)

示例:

试试下面的例子就明白了所有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 SMTP发送邮件遇到的一些问题及解决办法

Python SMTP发送邮件遇到的一些问题及解决办法

Python练习内容: SMTP是发送邮件的协议,Python内置对SMTP的支持,可以发送纯文本邮件、HTML邮件以及带附件的邮件。 Python对SMTP支持有smtplib和ema...

Pytorch 实现冻结指定卷积层的参数

python代码 for i, para in enumerate(self._net.module.features.parameters()): if i &...

如何用python整理附件

如何用python整理附件

目前我的文件夹中有500多份简历,如果我想知道一些信息,比如学校,学历之类的,我需要打开每一份word去查看,太耗时间了。这个时候python需要出马了。 目标 目前类似截图中的wo...

微信跳一跳小游戏python脚本

微信跳一跳小游戏python脚本

Python编写微信小游戏“跳一跳”的运行脚本,分享给大家。 更新了微信后发现了一款小游戏跳一跳,但是玩了一下午最高才达到200,每次差点破纪录后总是手抖就挂掉了,气的想要砸手机。闲来无...

python中通过预先编译正则表达式提高效率

前言 在re的正则表达式模块里,可以通过模块的方式来访问正则表达式,但是如果重复多次地使用正则表达式,最好是使用compile函数把正则表达式编译成对象RegexObject,这样会大大...