0

why is there a "del" function when your code could be edited later on?

for example: >>> spam = 2 >>> eggs = 3 >>> del spam >>> eggs = 4 >>> spam = 5 >>> print(spam * eggs) i know the answer is 20, though i dont understand why there is a "del spam" option

6th Mar 2017, 11:32 AM
Ash
4 Respuestas
+ 13
to get it out of memory, although I guess that doesn't matter as much with pythons garbage collection but really, del is useful for items in lists and dictionaries. there are things I couldn't have done if del didnt exist
6th Mar 2017, 11:57 AM
Ahri Fox
Ahri Fox - avatar
+ 4
You sometimes need to annoy your programmer friends... It's when you need it(Just kidding. Sometimes you don't need it anymore so you delete it)
6th Mar 2017, 4:28 PM
Ali Emir Kızıl
Ali Emir Kızıl - avatar
+ 4
Think embedded (Pi, Arduino, budget mobiles, Internet of Things)...limited resources...the reality for numerous Android users. SoloLearn's Python memory is artificially ~1MB. Variables reference memory. Garbage collection frees the memory when the memory's *reference count* reaches 0. https://docs.python.org/2.5/api/refcounts.html A commented program showing reference count changes: https://code.sololearn.com/ct7ToIVRI24y/?ref=app (In your example I did not check if Python reuses spam's reference if it's re-set before GC. That seems inefficient so I suspect not)
6th Mar 2017, 4:55 PM
Kirk Schafer
Kirk Schafer - avatar
+ 1
In some python editors, you do not have the ability to change your code, once you enter the next line. Hence. ........
6th Mar 2017, 11:35 AM
Meharban Singh
Meharban Singh - avatar