What is the id( ) function used for?

前端 未结 13 996
傲寒
傲寒 2020-11-22 10:51

I read the Python 2 docs and noticed the id() function:

Return the “identity” of an object. This is an integer (or long integer) which is

13条回答
  •  名媛妹妹
    2020-11-22 11:08

    As of in python 3 id is assigned to a value not a variable. This means that if you create two functions as below, all the three id's are the same.

    >>> def xyz():
    ...     q=123
    ...     print(id(q))
    ...
    >>> def iop():
    ...     w=123
    ...     print(id(w))
    >>> xyz()
    1650376736
    >>> iop()
    1650376736
    >>> id(123)
    1650376736
    

提交回复
热议问题