id( ) function question

Discussion in 'Python' started by raffaele ponzini, Oct 14, 2009.

  1. Dear all,
    I have a question concerning the output of the id() function.
    In particular since is should:
    ""
    Return the identity of an object. This is guaranteed to be unique among
    simultaneously existing objects. (Hint: it's the object's memory address.)
    ""
    i expect that for two differnt objects it returns two differnt adress in memory.

    Let's seee a correct case:
    >>> a=10
    >>> b=20
    >>> a is b

    False
    >>> id(a)

    9986060
    >>> id(b)

    9985940
    >>> c=a
    >>> c is a

    True
    >>> id(c)

    9986060
    >>> id(a)

    9986060

    And now a strange (for me) output:
    >>> d=10 #here i'm assingning a integer value to a fresh new variable d without any kind of link to the variable a
    >>> d is a

    True
    >>> d==a

    True
    >>> id(a)

    9986060
    >>> id(b)

    9985940
    >>> id(d)

    9986060
    >>> a=1e10
    >>> d=1e10
    >>> d is a

    False
    >>> id(a)

    11388984
    >>> id(d)

    11388920
    >>>


    --
    lele
    raffaele ponzini, Oct 14, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Vanns
    Replies:
    7
    Views:
    7,010
    Evan Carew
    Jan 21, 2004
  2. komal
    Replies:
    6
    Views:
    1,404
    msalters
    Jan 25, 2005
  3. Replies:
    2
    Views:
    892
    Bengt Richter
    Aug 1, 2005
  4. Giannis Papadopoulos

    Function pointer to void function and int function

    Giannis Papadopoulos, Sep 5, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,216
    Barry Schwarz
    Sep 5, 2005
  5. weafon
    Replies:
    1
    Views:
    288
    Diez B. Roggisch
    Jul 14, 2009
Loading...

Share This Page