List
Declare an empty list
Variable = [] = variable or List ()
Declare a list with data
Variable = [value, value ......] = List or variables (data containers) (data type conversion is essentially)
The basic operation of the list:
By: the index can not be used directly add
Delete: del variable [index]
Change: Variable [Index] = new value
Charles: Variable [Index]
View
list1 = [ 'sun', 'chi', 'to', 'ah']
RES = List1 [0:. 3]
Print (RES)
modified
list1 = [ 'sun', 'chi', 'to', 'ah']
List1 [0:. 3] = [ 'sun', 'may']
Print (List1)
increasing ( start value and end value must be the same, otherwise modify)
list1 = [ 'sun', 'chi', 'to', 'ah']
List1 [0: 0] = [ 'sun', 'may']
Print (List1)
Delete
list1 = [ 'sun', 'chi', 'to', 'ah']
del List1 [0:. 3]
Print (List1)
correlation function list:
the append (); add data to the list (added to the end surface)
INSERT (): added before the specified index list data
pop (): delete data at the specified index position in the list (the default when you remove the last hold data)
the Remove (): Removes the specified data in the list
clear (); clear the data
count (): number of times calculation specified in the list data present
Extend (): together the two lists, and "+" as the effect of
reverse () inverted list
sort (reverse = False): a sorted list (the default is ascending)
index (); obtaining a value in the index list
copy ():
shallow copy:
slicing the copy list [:]
copy of the caller object: list.copy ()
call: copy.copy () (Note; import to guide package copy)
deep copy:
copy.deepcopy () (Note: Import leader packet copy)
a listing of formula derived
basic derivation
result variable = [variables for variables in the container]
derivation with a condition determination
result = variable [variable for variables in Conditional expression container]
Analyzing the former conditions
Outcome variable = [Conditional Expression variable interval value true else false value for the variable in the container section]
multicycle listing derivation formula
outcome variable = [Variable 1 Variable 2 for calculating a variable in the container 2 in the container for variable]
Multi conditionally circulating derivations
Outcome variable = [Variable 1 Variable 2 for calculating a variable in the container 2 in the container for variable conditional expressions]
list traversal
for ...... container in
the list having a penetrating
list1=[1,2,3,4]
def func():
list1[0:]=[7,8,9]
print(list1)
func()