Unlike languages such as C++, in Mint the memory management model is quite simple.|
You already know how to create variables. Use the = operator.
To delete variables, use erase, followed by the names of one or more variables. Separate the names with commas.
x = 5 y = [20, 30] z = 300 erase x, y print z print y // Error: y is not defined. print x // Error: x is not defined.To erase every variable, use 'erase all'. To save the values of certain variables, use 'erase all except'.
x = "Hi" y = "Hello" z = "Goodbye" erase all except x print x print y // Not defined. print z // Not defined.Erase all can be used to free up memory taken up by existing variables, especially if your program is memory intensive.
You probably won't be using the erase keyword very often.
However, there is one other useful memory management tool that will swap the internal values of 2 variables:
flip a, b // Switches the values of a and b.You might notice that
temporary = x x = y y = temporaryBut looks far cleaner.
Previous Lesson: Objects
Next Lesson: Imports
Table of Contents