讲解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的pyecharts绘制各种图表详细(附代码)

python的pyecharts绘制各种图表详细(附代码)

环境:pyecharts库,echarts-countries-pypkg,echarts-china-provinces-pypkg,echarts-china-cities-pypk...

Python学习小技巧之列表项的排序

本文介绍的是关于Python列表项排序的相关内容,分享出来供大家参考学习,下面来看看详细的介绍: 典型代码1: data_list = [6, 9, 1, 3, 0, 10, 100...

深入理解NumPy简明教程---数组3(组合)

前两篇文章对NumPy数组做了基本的介绍,本篇文章对NumPy数组进行较深入的探讨。首先介绍自定义类型的数组,接着数组的组合,最后介绍数组复制方面的问题。 自定义结构数组 通过NumP...

TensorFlow索引与切片的实现方法

TensorFlow索引与切片的实现方法

索引与切片在Tensorflow中使用的频率极其高,可以用来提取部分数据。 1.索引 在 TensorFlow 中,支持基本的[𝑖][𝑗]…标准索引方...

Python超越函数积分运算以及绘图实现代码

Python超越函数积分运算以及绘图实现代码

编译环境:ubuntu17.04 Python3.5 所需库:numpy、scipy、matplotlib 下面是理想平面的辐射强度计算(课程大作业~~~) 1、超越函数积分运算 d...