讲解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 判断是否为正小数和正整数的实例

python 判断是否为正小数和正整数的实例 实现代码: def check_float(string): #支付时,输入的金额可能是小数,也可能是整数 s = str(st...

python实现键盘输入的实操方法

python实现键盘输入的实操方法

python中有指定的代码进行输入操作,所以今天就由小编来为大家介绍python怎么实现键盘输入。 第一首先打开电脑的python编辑工具。 再创建python项目。 第二然后应用sy...

基于python中pygame模块的Linux下安装过程(详解)

一、使用pip安装Python包 大多数较新的Python版本都自带pip,因此首先可检查系统是否已经安装了pip。在Python3中,pip有时被称为pip3. 1、在Linux和OS...

pyqt5之将textBrowser的内容写入txt文档的方法

如下所示: try: StrText = self.textBrowser.toPlainText() qS = str(StrText)...

Python实现求笛卡尔乘积的方法

Python实现求笛卡尔乘积的方法

本文实例讲述了Python实现求笛卡尔乘积的方法。分享给大家供大家参考,具体如下: 在数学中,两个集合X和Y的笛卡尓乘积(Cartesian product),又称直积,表示为X × Y...