1. The list is substituted for the array, and the type is undefined.
In the same list, the data type can be the same, can be different, even can add a new list within the list, the list can be empty, name=[];
2. Adding elements to a list
Append (x) method, but there can only be one parameter inside. A.append (x);
Extend (Y) method, there can be only one parameter, but the parameters can be a list, that is, you can add more than one time in this way.
The insert (x, Y) method, two parameters, the first represents the position of the insertion (position starting at 0), and the second represents the inserted data.
3. Getting elements from the list
Name[i], obtaining the element I;
4. Remove an element from the list
Remove (x) method, a parameter that removes the given element. If x is not in the list, then the error;
Del statement. Del Member[i];d el member delete all elements;
The Pop () method, with no arguments, indicates that the last element was thrown. Pop (i), throws the first element.
5. Once to get more than one element in the list, shard
MEMBER[I:J], get member[i]---member[j-1] element list;
I is an empty representation starting from 0; J is null for the last element, including the last element, and the i,j is null to represent the full value of the membere.
Note: member[:] The difference from member.
Example: list1=[3,2,1]
List2=list1;
list3=list1[:]
List1.sort ()
Last Printed: list1:1,2,3
list2:1,2,3, object reference
list3:3,2,1; a true copy.
6. Operator of the list
A. Comparison operator. Multiple element comparisons, such as comparison greater than, less than, if the first element is not equal, only the first element is compared, the condition is true, otherwise false, the subsequent element is not compared, if equal in the comparison after the element, if the comparison equals, then all elements must be equal, will be true.
B. The list can be added, stitching, equivalent to the Extend () method, but because the data type must be the same as the left and right side, so you can not pass the + sign; add a new element to the list;
X * n is also equivalent to the element inside the copy N,
C.x in y;x not in Y; Note: If element x exists within a list in List Y, the return value is false and can only be judged at the same level;
Where y can be a list in the list. Example y is list[1],x in; list[1], and if the condition described above is satisfied, it can be returned to true;
Note: If you access the values in the list, use List[i][j] to access them.
7. List other ways to use
The count (x) method. Calculates the number of times that X appears in the list.
Index (x), a parameter that represents the earliest position that x appears in the list. Index (X,I,J) represents the earliest position that x appears in the range of I-J elements in the list.
Reverse (), flip the list.
Sort (), sorting, default from small to large. Sort (reverse=true), from large to small. The actual sort can contain three parameters,
Python Learning 2--List