Variables store the data in memory. This means that there is a space in memory when creating variables. Based on the data type of the variable, the interpreter allocates the specified memory and determines what data can be stored in memory.
Variables in Python do not need to be declared , and the assignment of variables is the process of declaring and defining variables. Therefore, each variable must be assigned before it is used, and the variable will not be created until the variable is assigned.
The data structures in Python mainly include: sequences (such as lists, Ganso, strings), mappings (such as dictionaries), collections.
where Ganso and strings in the sequence are immutable types. Reason, official explanation:
One is performance:knowing this a string is immutable means we can allocate space for it at creation time, and the Storag E Requirements is fixed and unchanging. This was also one of the reasons for the distinction between tuples and lists.
Another advantage is this strings in Python is considered as "elemental" as numbers. No amount of activity would change the value 8 to anything else, and in Python, no amount of activity would change the Strin G "Eight" to anything else.
That is: The first one is better performance, at the time of the creation of the allocation of fixed-size memory, the second is the string, the number is the basic type, relative to other data types, the situation is less changed.
Data structures in Python