zoukankan      html  css  js  c++  java
  • python is operator

    来自:http://stackoverflow.com/questions/2438667/what-is-the-semantics-of-is-operator-in-python

    From the documentation:

    Every object has an identity, a type and a value. An object’s identity never changes once it has been created; you may think of it as the object’s address in memory. The ‘is‘ operator compares the identity of two objects; the id() function returns an integer representing its identity (currently implemented as its address).

    This would seem to indicate that it compares the memory addresses of the arguments, though the fact that it says "you may think of it as the object's address in memory" might indicate that the particular implementation is not guranteed; only the semantics are.

      works by comparing the object referenced to see if the operands point to the same object.

    >>> a =[1,2]

    >>> b = a >>> a is b True

    >>> c =[1,2]

    >>> a is c False

    c is not the same list as a therefore the is relation is false.

  • 相关阅读:
    Java基础五
    Java基础测试
    Java练习题
    Java基础四
    Java基础三
    Java基础二
    Java基础一
    大数据讲解
    python笔记之函数 二
    iOS UICollectionView的使用(用storyboard和xib创建)
  • 原文地址:https://www.cnblogs.com/youxin/p/3060525.html
Copyright © 2011-2022 走看看