One, the meta-group
1. Definition of tuples, creating
tuple = ('apple','banana','Grange' ,'orange','anguo','C + + ')
Note: The tuple is comprised of 6 elements, separated by commas.
tuple = ('apple',)
Note: One element followed by a comma
2. Meta-group access
(1) The index is a number in each other's brackets, and the index is also called subscript.
tuple = ( " apple , " banana , " grange , " orange , " anguo , " c++ " ) print (tuple[1 ]) print (tuple[2 ]) print (tuple[3])
Note: Tuples cannot add or remove any elements.
(2) Gets the value of the tuple (negative index or tile index)
Second, List
1, the definition of the list, create,
list = ['apple','banana','Grange' ,'orange','anguo','C + + ']
Note: addition and deletion of the change
List = ['Apple','Banana','Grange','Orange','Anguo','C + +']list.append ("C") at the end of the add element List.insert (1,"C") to insert an element into the list list.remove ("Anguo") Delete this element List.pop (1) to delete the specified element list[1]="Php"Add an ordinal equal to the modified value
2, the use of the list
(1) List and tuple are very similar, support negative index, Shard, multivariate list
names=['Michale','Bob','TRACY'] forIinchnames:Print(i) Note: Circular output List Names=('Michale','Bob','TRACY') forIinchnames:Print(i) Note: cyclic output tuples
(2) Find, sort, reverse
Find (2 ways). The index method returns the position of the element in the list, and "in" to determine whether the element is in the list.
List = ['Apple','Banana','Grange','Orange','Anguo','C + +']Print(List.index ('Apple'))Print(List.index ('C + +') Note: The index of the printed element is also:Print("Grange"inchlist) Note: Judging'Grange'is in the list
Sort, invert
List = ['Apple','Banana','Grange','Orange','Anguo','C + +']list.sort ()Print("Print this result:", List) Note: Sort sortlist.reverse ()Print("Print this result:", List) Note: Invert reverse
Third, the dictionary
Create, Access
dict={"a":"Python","b":"Php","C":"Jave","D":"C","e":"C + +"}Print(dict["a"]) Note: Get the corresponding value "Python" by Index "a": Tuple and list index are numbers. The dictionary is the "key" index, and the "key" index can be written as a number
Dictionary loop output:
dict={"a":"Python","b":"Php","C":"Jave","D":"C","e":"C + +"}Print(dict["a"]) forKvinchDict.items ():Print("the dictionary output is"K'-', v) Note the answer: The dictionary output is a-the python dictionary output is e-C + +the dictionary output is C-Jave Dictionary output to D-c dictionary output to B-PHP
Python tuple list Dictionary base analysis: