All the following content is based on memory address
Immutable data type: When the value of the corresponding variable of this data type changes, then its corresponding memory address will also change. This data type is called an immutable data type.
Variable data type: When the value of the corresponding variable of this data type changes, then its corresponding memory address does not change. This data type is called a variable data type.
Summary: The address changes after the immutable data type is changed, but the address does not change when the variable data type is changed
String
b = 'djx' print(id(b),type(b)) b = 'djx1996' print(id(b),type(b)) 535056476344 <class 'str'> 535056476624 <class 'str'>
We can find that when the data changes, the memory address of the variable changes, then the string is an immutable data type.
The above is the detailed content of Is python string a variable type?. For more information, please follow other related articles on the PHP Chinese website!