1. Lists (list)
A list is a data structure that handles a set of ordered items, that is, you can store a sequence of items in a list.
The items in the list should be included in square brackets so python knows you are specifying a list. Once you have created a list, you can add, delete, or search for items in the list. Since you can add or delete items, we say that the list is a mutable data type, that is, the type can be changed, and the list can be nested.
Instance:
#coding =utf-8#author:rxs002animalslist = [' Fox ', ' Tiger ', ' rabbit ', ' Snake ']print (' I don't like these ', Len (animalslist ), ' animals ... ') for item in Animalislist:print (item) print (' \ n operation ') #对列表的操作, add, remove, sort animalslist.append (' pig ') del Animalslist[0]animalslist.sort () #sort是排序for I in range (0,len (animalslist)): Print (Animallist[i])
Execution Result:
I don't like these 4 animals...fox Tiger rabbit snake after Operation pig rabbit Snake Tiger
2, Ganso (tuple)
Ganso and lists are very similar, but Ganso is immutable. That is, you cannot modify the ancestor.
Ganso items are defined by commas separated by parentheses. Ganso usually makes it possible for a statement or user-defined function to safely take a set of worthwhile times, that is, the value of the Ganso being used does not change. Ganso can be nested.
>>>zoo = (' Wolf ', ' Elephant ', ' Penguin ') >>>zoo.count (' Penguin ')
1
>>>zoo.index (' Penguin ')
2
>>>zoo.append (' pig ')
execution Error: because the meta-ancestor cannot be modified
3. Dictionary (Dictionary)
The dictionary is similar to the Address book where you find the address and contact details by contact name, i.e. we associate the key (first name) with the value (details) . Note that the key must be unique, as if two people happen to have the same name, you cannot find the correct information.
Key-value pairs are tagged in the dictionary in such a way d={key:value,key2:value2}.
that their key/value pairs are separated by colons, and each team is delimited by commas, all of which are included in curly braces. Also, remember that the keys/values in the dictionary are not sequential. If you want a particular order, then you should sort them before using them.
Instance:
#coding = UTF-8 #author: Rxs002dict1 = {' Zhang ': ' hellos ', ' Wang ': ' Wangbaoqiang ', ' li ': ' Bingbing ', ' Zhao ': ' Vicki '} #字典的操作, add, delete, print dict1[' Huang '] = ' Huang Jiaju ' del dict1[' Zhao ']for firstname,name in Dict1.item (): Print Firstname,name
Execution Result:
Li Bingbing Wang Wangbaoqiang Huang Huang Jiaju Zhang Hellos
Summarize
This is about Python in the meta-ancestor, list and dictionary of the introduction and the difference, I hope that you learn to use Python can be helpful.