+ 1

Can u explain about this code? , i did'nt understand about this code

x=11 print (id(x)) x=x+1 print (id(x))

26th Oct 2022, 6:33 AM
Gopi M
Gopi M - avatar
4 ответов
+ 2
id(obj) returns the unique identity for object. cpython uses the memory address of the object when you initialized x = 11 Python creates object inside memory with value 11 and x refers to it x = x + 1 here python creates another object 11 + 1 = 12 now x refers to another object and previous object get cleared by garbage collector.
26th Oct 2022, 6:39 AM
Ratnapal Shende
Ratnapal Shende - avatar
+ 2
garbage collector is a program which free up the memory by removing dead objects whenever we create object python keeps count on it when count is 0 garbage collector get invoked and removes the object when their is no reference to that object .
26th Oct 2022, 6:42 AM
Ratnapal Shende
Ratnapal Shende - avatar
0
Can you explain what is garbage collector?
26th Oct 2022, 6:40 AM
Gopi M
Gopi M - avatar
0
Yeah! Thanks its help me a lot.........👍
26th Oct 2022, 6:44 AM
Gopi M
Gopi M - avatar