filmov
tv
Python 3.12 - full course - id
![preview_player](https://i.ytimg.com/vi/U8ami86TTGE/maxresdefault.jpg)
Показать описание
Welcome!
Python 3.12 complete course - id - copy vs. reference (shallow copy)
In [38]: # id - copy vs reference
In [39]: a = 5
In [40]: id(a)
Out[40]: 10815336
In [41]: id?
Signature: id(obj, /)
Docstring:
Return the identity of an object.
This is guaranteed to be unique among simultaneously existing objects.
(CPython uses the object's memory address.)
Type: builtin_function_or_method
In [42]: b = 3
In [43]: id(a)
Out[43]: 10815336
In [44]: id(b)
Out[44]: 10815272
In [45]: id(a) == id(b) # == question not assignment (= vs ==)
Out[45]: False
In [46]: x = ["a", "p", "p", "l", "e"]
In [47]: y = x
In [48]: id(x)
Out[48]: 139741025467776
In [49]: id(y)
Out[49]: 139741025467776
In [50]: id(x) == id(y)
Out[50]: True
In [52]: id(x)
Out[52]: 139741025467776
In [53]: id(y)
Out[53]: 139741015335488
In [54]: id(x) == id(y)
Out[54]: False
Python 3.12 complete course - id - copy vs. reference (shallow copy)
In [38]: # id - copy vs reference
In [39]: a = 5
In [40]: id(a)
Out[40]: 10815336
In [41]: id?
Signature: id(obj, /)
Docstring:
Return the identity of an object.
This is guaranteed to be unique among simultaneously existing objects.
(CPython uses the object's memory address.)
Type: builtin_function_or_method
In [42]: b = 3
In [43]: id(a)
Out[43]: 10815336
In [44]: id(b)
Out[44]: 10815272
In [45]: id(a) == id(b) # == question not assignment (= vs ==)
Out[45]: False
In [46]: x = ["a", "p", "p", "l", "e"]
In [47]: y = x
In [48]: id(x)
Out[48]: 139741025467776
In [49]: id(y)
Out[49]: 139741025467776
In [50]: id(x) == id(y)
Out[50]: True
In [52]: id(x)
Out[52]: 139741025467776
In [53]: id(y)
Out[53]: 139741015335488
In [54]: id(x) == id(y)
Out[54]: False