First, supplements1. All the data in Python is built around the concept of objects.
Objects contain some basic data types, such as numbers, strings, lists, tuples, dictionaries, and so on, so that all the data stored in the program is an object
Each object has the following characteristics:
For example:a = 1
An identity (using the ID () command to view the address of this object in memory)
A type (with the type () command to see the types of this object)
A value, which is viewed by the variable name. The value referenced by the variable name, this example is 1)
2. Strings can be traversed by while and for loops. They are traversed based on the index of the string . 3, the concept of factory function
Defining a data type, such as: x = 1, is actually called x = Int (1), which means that any integer type is the result of calling the Int () method, which means that an int () method is used to mass-produce many integers, and so are the other data types, which is the concept of the factory function.
4. Variable data types and immutable data types
When you define a data type, it creates its ID, type, and value.
If the ID is changed, it is equal to creating another data type, which is not related to the original data type. So the ID doesn't change.
If the type is changed, it is equivalent to the memory opens up a space to save a value in, and the original data type is not related, so the type can not be changed
The only variable is value. So judging that this data type is mutable, look at value.
So come to the conclusion that distinguishing whether a data type is mutable or immutable must be done with the ID and type unchanged , just by looking at its value.
About variable make a plain analogy--rent a house :
Landlord a rents his own house, and after the tenant expires, the next tenant will live in. The house and landlord a remain the same, just the tenant change, this House is still landlord A's, this is like Python's mutable data type. The house and the landlord are equivalent to the ID and type, the tenant is equivalent to value, only the tenant changes, this is the variable data type
Example: Changing the value of an integral type to see if an integral type is a mutable type
As shown, after changing the value of an integral type, the previous ID is changed, and the visible integer type is not a mutable type.
The above view applies to all Python data types
5. List(1) Definition
Cases:
L = []
This is the list, which can hold multiple comma-delimited values of any Python data type, which is called an element in the list, and the list is a mutable data type
(2) The value of the list:
The value of the list is the same as the value of the string, and the value is evaluated by index.
Example 1: Take out the 2nd element in the list below
L = ["Xiaobai", "haha", [n/a], "hello"]
print (l[2]) # by Adding the index value to the brackets, you can remove the elements from the list.
Example 2: Remove the elements from the list below [A] 2 elements in a
L = ["Xiaobai", "haha", [n/a], "hello"]
Print (l[3] [1]) # finds the index position where [three-way] is located, and then takes the 2nd element out.
(3) Type of list
Proof: List is variable data type
second, variable assignment operation
1. Comparison of identities, comparison of types, comparison of values: is
Cases:
2, variable assignment operation: no return value
x = 1 # This is the assignment operation of the variable
Print (x=1) # If direct printing will be error: TypeError: ' x ' is a invalid keyword argument for this function
3, chain-assigned value
Cases:
10
Print (X,Y,Z,A,B)
Printed Result: 10 10 10 10 10
4. Multi-value Assignment
Python third day (not finished)