python data type - variable data types and data types immutable

In python data type contains the following categories:

1. Digital type (Number): integer (int), float (float), complex (Complex)

2. Type String (String)

 

 

3. List (List)

4. collection (the Set)

The tuple (Tuple)

6. Dictionary (Dict)

Belonging to the above type of variable types are: Dict, List, Set

An immutable type is: Boolean, Tuple, String, Number

Analyzing the data type is the variable type is immutable data to determine whether a memory variable value.

Such as digital type

num1 = 5
num2 = 5
print(id(num1))
print(id(num2))

num1 = 6
num2 = 6
print(id(num1))
print(id(num2))

The above result is output code

5 can be seen above the num1 and num2 assigned to the memory when the address is the same, assigned to the num1 and num2 6 when the memory address is the same, num1 and num2 receiving memory 5 and 6 will change, and the memory address correspondence value is not changed, and this is called data type immutable

Then look at the variable data type List

list = [1,2,3]
print(id(list))

list[0] = 3
print(id(list))

The above result is output code

Can be seen that the value of the change list memory address has not changed, this variable is the type of data

My personal conclusion is: When changing the value of the memory address also followed occurs change is immutable data types, occurs when changing memory address value is variable data type change will not occur.

The above represents only my personal opinion, if wrong please the god pointing

 

Released three original articles · won praise 0 · Views 222

Guess you like

Origin blog.csdn.net/qq_37398847/article/details/104398966