Home > Blockchain >  /Python don't understand, ask a small problem about tuples
/Python don't understand, ask a small problem about tuples

Time:09-21

About tuples are immutable:

(1) the so-called tuples immutable refers to a tuple is pointing to the contents of the memory of the immutable, also is the element in a tuple cannot be changed,
(2) if the yuan group, is to assign a value, which allowed,

 & gt;> Obj=(1, 2, 3, 4) 
> Id (obj)
52092432

> Obj [1]=99
Traceback (the most recent call last) :
The File "& lt; Pyshell# 16 & gt;" , the line 1, the in & lt; module>
Obj [1]=99
TypeError: 'the tuple object does not support the item the assignment

> Obj=(' a ', 'c', 'e')
> Id (obj)
8331464



I want to ask, after that, the original obj binding by the tuple, namely (1, 2, 3, 4) of this, it still exists in memory? Still use memory? Thank you big!!!!

CodePudding user response:

Before answering the question of the building Lord, speak a little Python first GC (Garbage Collection), the mechanism of Garbage Collection is, now in addition to the C/C + + language, basically have GC, including Golang, Java, Python, Ruby, Python Garbage Collection mainly USES a reference counting mode, is when an object is not quoted, it count goes to zero, then the system at the appropriate time object memory recovery,

Back to the question of the building Lord, as the obj is to point to to (' a ', 'c', 'e'), (1, 2, 3, 4) the tuple object has no quotes, which means it's counting has been changed to zero, it is useless, the system will automatically recycling, at the right time can don't tube it,

CodePudding user response:

Lord, thank you very much layer careful answer, I understand, I just turn around, c some still don't understand!

CodePudding user response:

reference 1st floor rrrr336 response:
before answering the question of the building Lord, you said a little Python GC (Garbage Collection), the mechanism of Garbage Collection is, now in addition to the C/C + + language, basically have the GC, including Golang, Java, Python, Ruby, Python Garbage Collection mainly USES a reference counting mode, is when an object is not quoted, it count goes to zero, then the system at the appropriate time object memory recovery,

Back to the question of the building Lord, as the obj is to point to to (' a ', 'c', 'e'), (1, 2, 3, 4) the tuple object has no quotes, which means it's counting has been changed to zero, it is useless, the system will automatically recycling, at the right time can don't tube it,
thank you very much for the careful answer, layer of main I understand! Thank you very much!

CodePudding user response:

reference 1st floor rrrr336 response:
before answering the question of the building Lord, you said a little Python GC (Garbage Collection), the mechanism of Garbage Collection is, now in addition to the C/C + + language, basically have the GC, including Golang, Java, Python, Ruby, Python Garbage Collection mainly USES a reference counting mode, is when an object is not quoted, it count goes to zero, then the system at the appropriate time object memory recovery,

Back to the question of the building Lord, as the obj is to point to to (' a ', 'c', 'e'), (1, 2, 3, 4) the tuple object has no quotes, which means it's counting has been changed to zero, it is useless, the system will automatically recycling, at the right time can don't tube it,
bosses right.
  • Related