美文网首页
编程字典-Python id 运算符实例

编程字典-Python id 运算符实例

作者: 茶茶点 | 来源:发表于2018-11-07 12:35 被阅读0次

    python id 运算符

    #!/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"

    更多实例:http://codingdict.com/article/19147

    相关文章

      网友评论

          本文标题:编程字典-Python id 运算符实例

          本文链接:https://www.haomeiwen.com/subject/nzamxqtx.html