the type and object of a variable value
The program needs to deal with a lot of state, so there are different types of variable values, x= ' Egon ', the variable value ' Egon ' is stored in memory, binding a name X, the value of the variable is the data we want to store.
All data in Python is built around the concept of objects that contain some basic data types: numbers, strings, lists, tuples, dictionaries, etc.
All the data stored in the program is an object,
An object (such as A=1) is:
An identity (ID)
A type
A value (viewed by variable name a)
Two mutable objects and immutable objects
once the instance is created, the identity and type are immutable,
If the value is not modifiable, the object is immutable
If the value can be modified, it is mutable to the
three Container Object
An object contains a reference to another object, which is called a container or collection
Four Properties and methods for objects
A property is the value of an object, which is a function that performs certain operations on the object itself when called, using the the. Operator can access the properties and methods of an object, such as
A=3+4j
A.real
b=[1,2,3]
B.append (4)
Five identity comparison, type comparison, value comparison
X=1
Y=1
X is y #x与y是同一个对象 and is a comparison of ID, which is the identity
Type (x) is type (y) #对象的类型本身也是一个对象, so you can compare the identities of two object types with IS
x = = y #== compares the values of two objects for equality
Six assigning operations to variables
The difference from the C language is that the variable assignment operation has no return value
Chained assignment: y=x=a=1
Multi-value assignment: x,y=1,2 x,y=y,x
Incremental assignment: X+=1
Seven Decompression sequence types
To assign values to multiple variables at the same time, it is important to note that the variable names are separated by commas and, of course, the same operation. You must ensure that the number of sequence elements unpacked is equal to the number of variables on the left side of the equals sign. Do not want to get the character can be used _ instead, if there is a character do not want to take, use *_ instead
Definition of a list of eight list types: the brackets contain multiple values, each of which is called an element, can be any data type, can be a string, a number, or a sub-list. Used to hold multiple values.
List creation: list_test=[' LHF ', ' OK '
Or
List_test=list (' abc ')
Or
List_test=list ([' LHF ', ' OK ')
Common actions for lists: Index
Slice
Append append Overall add to original list go to u
Delete Pop
length Len
slices
Loops
contains in
inserting insert
List of other actions: Index lookup
Count Statistics number
Extend extension
Remove removes several from left to right to remove the first one
Sort sorts
Reverse reversal
Nine tuples
Tuple definition: Similar to the list, the brackets are replaced by parentheses, and the element can be any type
The attributes of a tuple are immutable. Immutable refers to an element that is immutable, while a sub-list within it can be modified.
Common operations of ten dictionaries
Dictionary definition: A directory page corresponds to a type (key:value), and multiple elements can be created. Note Key must be an immutable type. It can also be said to be a hash type. The value can be changed.
Dictionary values are unordered.
Nested use of dictionaries: example diagram
11 Classification of values
1 Variable non-volatile
mutable: List. Dictionary
Immutable: Numbers, strings, tuples
2 Number of stored values
A value: A number, a string
Multiple values (container type): List, meta-ancestor, dictionary
3 How to take value
Direct value: Number
Sequence type: string, meta-ancestor, list
Mapping Type: Dictionary
15th day walking into the computer (Python basic three)