python's variable and immutable datatypes
1. What is variable and immutable
Let's start by saying what mutable immutable Python data is.
We all know that when you define a variable, you create a memory space, put the value in it, and then the variable name holds the memory address of that memory space. Now we can explain.
- Variable type: that is, the value of this data type is going to change the value of this data type without changing this piece of memory space.
- Immutable types: when the change is worthwhile, a new piece of memory space will be requested, and it will no longer be the same as the original piece of memory space.
2. Immutable types
What are some of the data types that are immutable?
In Python design, integers, floats, strings, and metazoans are immutable types, and this can be verified by the id() method. There are some underlying operations involved that I don't understand.
- Integers.
- string (computer science)
- floating point type
- Great Ancestor (posthumous title, e.g. for the founder of a dynasty)
- Boolean type
3. Variable types
Of all python's data types, dictionaries, lists, and mutable collections are mutable types, and when you change the value of an element, you change the corresponding memory address in the memory space where that data type resides.
- listings
- dictionaries
- set (mathematics)
Knowledge point expansion:
1. Explanation of terms
All of the following is based on memory addresses.
Immutable data type: When the value of the corresponding variable of this data type changes, then its corresponding memory address also changes, for this data type, it is called immutable data type.
Variable data type : A data type in which the value of the corresponding variable is changed without changing its corresponding memory address is called a variable data type.
Summarize: the address changes after the immutable data type changes, and the address does not change after the variable data type changes.
2. Classification of data types
The data types in python are: integer, string, tuple, set, list, dictionary. Let's see if they are immutable or mutable datatypes with an example.
to this article on the python data type variable immutable knowledge points summarized article is introduced to this, more related python data type variable immutable content please search my previous articles or continue to browse the following related articles I hope that you will support me more in the future!