Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Intricacies of Aliasing
#2
id(some_list) always gives you the address of list object in memory,not what the list contain.
Since lists are mutable they create new object in memory every time.
>>> id([])
13622648
>>> id([])
8717336
>>> id([])
13621328
The object integer inside list container is immutable and can point to same place in memory.
>>> x = [1]
>>> y = [1]
>>> id(x) == id(y)
False
>>> # is use id()
>>> x is y
False
>>> # == dos not
>>> x == y
True
>>> # Test integer object inside of list
>>> id(x[0]) == id(y[0])
True
>>> 
>>> help(id)
Help on built-in function id in module builtins:

id(obj, /)
    Return the identity of an object.
    
    This is guaranteed to be unique among simultaneously existing objects.
    (CPython uses the object's memory address.)
Reply


Messages In This Thread
Intricacies of Aliasing - by ClassicalSoul - Mar-01-2019, 11:57 AM
RE: Intricacies of Aliasing - by snippsat - Mar-01-2019, 12:58 PM
RE: Intricacies of Aliasing - by scidam - Mar-01-2019, 01:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  signal anti-aliasing frohr 0 1,168 May-23-2022, 05:18 PM
Last Post: frohr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020