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

yipeiwu_com6年前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 以其简单易懂的语法格式与其它语言形成鲜明对比,初学者遇到最多的问题就是不按照 Python 的规则来写,即便是有编程经验的程序员,也容易按照固有的思维和语法格式来写...

Python提取频域特征知识点浅析

Python提取频域特征知识点浅析

在多数的现代语音识别系统中,人们都会用到频域特征。梅尔频率倒谱系数(MFCC),首先计算信号的功率谱,然后用滤波器和离散余弦变换的变换来提取特征。本文重点介绍如何提取MFCC特征。 首先...

python for 循环获取index索引的方法

使用 enumerate 函数 可以返回下标。 例如 for inx, val in enumerate(['uyy', 'dfdf']): print(inx) pri...

TensorFlow高效读取数据的方法示例

概述 最新上传的mcnn中有完整的数据读写示例,可以参考。 关于Tensorflow读取数据,官网给出了三种方法: 供给数据(Feeding): 在TensorFlow程序运行的每...

浅谈flask中的before_request与after_request

本文主要是对flask中的before_request与after_request用法做一个简单的分析,具体实例和介绍如下。 使用before_request 和 after_reque...