讲解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中的标识运算符请关注haodaima.com其它相关文章!

您可能有感兴趣的文章
Python中字典与恒等运算符的用法分析

Python学习笔记之列表和成员运算符及列表相关方法详解

简单了解python关系(比较)运算符

简单了解python中对象的取反运算符

Python3.5运算符操作实例详解