讲解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 对key为时间的dict排序方法

如下所示: import time def date_compare(item1, item2): t1 = time.mktime(time.strptime(item1,...

python之pexpect实现自动交互的例子

Pexpect 是 Expect 语言的一个 Python 实现,是一个用来启动子程序,并使用正则表达式对程序输出做出特定响应,以此实现与其自动交互的 Python 模块。 Pexpec...

Python错误: SyntaxError: Non-ASCII character解决办法

Python错误: SyntaxError: Non-ASCII character解决办法

Python错误: SyntaxError: Non-ASCII character解决办法 (1)问题描述   在写Python代码的过程中,有用到需要输出中文的地方,但是...

简单使用Python自动生成文章

  为了应付某些情况,需要做17份记录。虽然不很重要,但是17份完全雷同也不很好。大体看了一下,此记录大致分为四段。于是决定每段提供四种选项,每段四选一,拼凑成四段文字,存成一个文件。文...

PyQt5每天必学之布局管理

PyQt5每天必学之布局管理

在GUI编程中有一个不容忽视的部分,那就是布局管理。布局管理掌控着我们的控件在应用程序窗口如何摆放。布局管理可以通过两种方式来完成。我们可以使用绝对定位或布局类两种方法控制程序窗口中的控...