A list is a built-in data type that is an ordered set of elements that can be added and removed at any time.
classmates = [' Michael ', ' Bob ', ' Tracy '];
1, Len (classmates): Returns the number of list elements 3
2. Index: classmates[0] ' Machael '
Get the last element: Classmates[len-1] or classmates[-1]
The same as the bottom 2nd: classmates[len-2] or classmates[-2]
3. Append element: Append to end Classmates.append (' Adam ')
Insert element at specified location Classmates.insert (1, ' Jack ')
4. Delete element: Delete last element Classmates.pop () returns the value of a pop
Removes the element at the specified location Classmates.pop (1)
5. Replacement element: classmates[1] = ' Sarah '
6. The data type of the elements in the list can be different: L = [' Apple ', 123,true]
7, the elements in the list can also be another list:s = [' Python ', ' Java ', [' asp ', ' php '], ' scheme ']
Len (s) 4 S can be viewed as a two-dimensional array, accessing ' ASP ' s[2][0]
8, if L = [], then Len (L) 0
A tuple tuple is similar to a list, but cannot be modified once the tuple is initialized
Classmates = (' Michael ', ' Bob ', ' Tracy ')
At this time classmates this tuple can not be changed, that is, can not be inserted, deleted, only read, and the same as list.
1, t = (+)
2, T = ()
3, T = (1,)
Python-list and tuple