Python list
Introduction to sequence types (sequence)
String str
Lists List
Ganso tuple
Concept:
Lists are made up of a series of specific elements that may not have any association between them, but they have a sequential relationship
Lists can change the values of individual elements
A list is a container.
Empty list: L = [] # empty list
L = List () # empty lists, is a function
Create a non-empty list:
L = [1,2,3,4,5]
List of generated functions lists ():
List () generates an empty list equal to [];
List (iterable) with an iterative object to initialize the lists
Example:
1>>> l=list (Range (11))2>>>L3[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]4>>>5>>> s='ABCDEFG'6>>> l=list (s)7>>>L8['a','b','C','D','e','F','g']9>>>
List1
List of operators
+, + =, *, *=
Description: The + operator is used for splicing lists, and the + = operator is used for the new list generated from the original list and the right-hand list (x = X+y equals x +=y)
The * operator is used to generate duplicate lists; * = operator is used to generate duplicate lists for the original list and to change the binding of variables;
1>>> x=[1,2,3]2>>> y=[4,5,6]3>>> z = x +y4>>>Z5[1, 2, 3, 4, 5, 6]6>>>Len (z)768>>> m = y +x9>>>mTen[4, 5, 6, 1, 2, 3] One>>>Len (m) A6 ->>>
+ number Stitching
1 >>> x=[1,2,3]2 >>> y=[4,5,6]3 >>> x + = y 4 >>> x5 [1, 2, 3, 4, 5, 6]6 >>> y 7 [4, 5, 6]8
+ = number stitching
1 >>> [+] * 32 [1, 2, 1, 2, 1, 2]3 >>> 3 * [4] > [1, 2, 1, 2, 1, 2]5
*
1 >>> x = [x-ray]2 >>> *= 43 >>> x 4 [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]5
*=
Relational (comparison) operators for lists:
> >= < <= = = =!
1>>> x = [A]2>>> y = [2,3,4]3>>> x! =y4 True5>>> x >y6 False7>>> x <y8 True9>>> x = =yTen False One>>> [3,2,1] = = [] A False ->>> [1,' Both'] < [' Both', 1] - Traceback (most recent): theFile"<pyshell#59>", Line 1,inch<module> -[1,' Both'] < [' Both', 1] -Typeerror:unorderable Types:int () <str () ->>>#strings and lists are not comparable
View Code
The path to Python, sixth: Introduction to Python and Basics 6