Data type (cont.)
1 List
Definition: [] separated by commas, by index, storing various data types, each position represents an element
Characteristics
1 can hold multiple values
2 can modify the corresponding value of the index position, variable
3 list elements are defined in left-to-right order, subscript is accessed sequentially from 0, ordered
1 list_test[' LHF, ' k, ' OK ']2 or 3 list-test=list (' abc ') 4 or 5 list_test=list ([' LHF ', ' + ', ' OK '])
List common actions
Index
Slice
Additional
Delete
Length
Slice
Cycle
Contains
2 tuples
Definition: Similar to a list, except [] Change to ()
Features: 1 can hold a value of 2 immutable 3 The tuple element is defined in the order from sitting to right, the subscript is accessed sequentially from 0, ordered
Tuple creation
1 age= (11,22,33,44,55) 2 or 3 ages=tuple ((11,22,33,44,55))
Tuples Common operations
Index
Slice
Cycle
Length
Contains
3 Dictionaries
Definition: (key:value1,key2:value2), key-value structure, key must be hash
Attribute 1 can hold multiple values 2 can modify the value corresponding to the specified key, can be changed to 3 unordered
Dictionary creation
person={' name ': ' SB ', ' Age ': 18} or Person=dict (name= ' SB ', age=18) person=dict (name= ' SB ', age=18) person=dict ([' Name ', ' SB '],[' age ',] {}.fromkeys (seq,100) #不指定100 default to None Note "Dic={}.fromkeys ([' K1 ', ' K2 '],[])" dic{' K1 ': [1], ' K2 ': [1] }
Dictionary common Operations
Index
New
Delete
Key, value, key-value pairs
Length
4 Collection
Definition: A collection of different elements, a set of unordered permutations of hasha values that can be used as a dictionary key
Characteristics:
1 The purpose of the collection is to store different values together between different sets for relational operations, without having to tangle the individual values in the set
Creation of collections
{1,2,3,1}
Or
Define a mutable collection set
>>>set_test=set (' Hello ')
>>>set_test
Frozenset ({' 1 ', ' 2 ', ' h ', ' O '})
Collection common operations: relational operations
Inch
Not in
==
!=
<,<=
>,>=
|,|=: The collection
&.&=: Intersection
-,-=: Difference Set
^,^=: Symmetric difference Set
Python Jobs (data type Cont.)