First, List
The form of a list is denoted by [], [] There are ', ', ' separate list contents. Lists can also be nested.
Syntax: eg.name1 = [' 1lo ', ' 2ng ', ' 3er ', ' 4long '];
Print (NAME1);
Print: [' 1lo ', ' 2ng ', ' 3er ', ' 4long ']
Insert, add, Delete, change, and find actions on a list.
1. Insert (Pos,val) POS is the position index of the list, Val is the added content
Name1.insert (1, ' 5xxx ');
Print (NAME1);
Print: [' 1lo ', ' 5xxx ', ' 2ng ', ' 3er ', ' 4long ']
2. Add append (val) to add content at the end of the list
Name1.append (' 6xxx ')
Print: [' 1lo ', ' 5xxx ', ' 2ng ', ' 3er ', ' 4long ', ' 6xxxx ']
3. Delete del, Remove,clear,pop
A, Del can specify the deletion of the corresponding position of the element
Del Name1[3];
Print: [' 1lo ', ' 5xxx ', ' 2ng ', ' 4long ', ' 6xxx ']
B. Remove removes the specified element
Name1.remove (' 5xxx ');
Print: [' 1lo ', ' 2ng ', ' 4long ', ' 6xxx ']
C, pop remove the last element
Name1.pop ();
[' 1lo ', ' 2ng ', ' 4long ']
D, clear empty list elements
Name1.clear ();
Print: "Empty"
NAME1 = ['1lo','2ng','3er','4long'];Print(name1); Name1.insert (1,'5xxx');Print(name1); Name1.append ('6xxx');Print(name1);delName1[3];Print(name1); Name1.remove ('5xxx');Print(name1); Name1.pop ();Print(name1); Name1.clear ();Print(NAME1);
4. Change (Modify)
name1[2]= ' 7eee '; #不存在的话, the system will error
Print: [' 1lo ', ' 2ng ', ' 7eee ', ' 4long ']
5. Find
Print (Name1.index (' 7eee '));
Get Subscript: 2
Two, the meta-group
A tuple is a list that cannot be changed. Also called a read-only list.
Only count, and index two operations.
Third, the dictionary
A dictionary of Key-value data types. The same dictionary can also be nested.
Grammar: eg.
Info1 = {
' stu1101 ': ["Tenglan Wu", "35", "155"],
' stu1102 ': ["Longze Luola", "36", "160"],
' stu1104 ': ["Xiaoze Maliya", "30", "165"],
}
Features of the dictionary:
Dict is disordered.
Key must be unique
Print: {' stu1104 ': [' Xiaoze Maliya ', ' ['] ', ' 165 '], ' stu1101 ': [' Tenglan Wu ', ' ' 155 ', ' stu1102 ']: [' Longze Luola ', ' 36 ', ' 160 ']}
At the same time the dictionary can implement multilevel nesting.
Usage of the Python list tuple dictionary