讲解Python中的标识运算符

yipeiwu_com5年前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 pycharm 同时加载多个项目的方法

Python pycharm 同时加载多个项目的方法

在pycharm中只能一个项目存在,想打开另一个项目只能建一个新窗口或者把当前窗口覆盖掉。 在pycharm中其实可以同时打开多个项目: 1、file->setting->p...

Django中间件工作流程及写法实例代码

Django中间件工作流程及写法实例代码

熟悉web开发的同学对hook钩子肯定不陌生,通过钩子可以方便的实现一些触发和回调,并且做一些过滤和拦截。 django中的中间件(middleware)就是类似钩子的一种存在。下面我们...

对django layer弹窗组件的使用详解

父层: <div class="col-xs-12"> <div class="box"> <div class="box-header...

Python箱型图绘制与特征值获取过程解析

Python箱型图绘制与特征值获取过程解析

这篇文章主要介绍了Python箱型图绘制与特征值获取过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 它主要用于反映原始数据分布...

wxpython+pymysql实现用户登陆功能

wxpython+pymysql实现用户登陆功能

wxpython最为一款python GUI库,由于简单和轻便外加强大的功能而受到很多python爱好者的喜爱,pymysql作为python3.x版本连接mysql库,应用也非常广泛。...