Now in the internship, long time useless python, today in the Java project with the HashMap let me associate with the Python dictionary, write some knowledge of Python dictionary, review review.
Dictionary: Key-to-value mapping relationship, dictionary is unordered, dictionary key is immutable type, such as int, str, float,tuple ...
1. Create a dictionary
(1) The first way to create a dictionary, once to the full
>>> user = {'ID': 1000,'name':'SCD','Password':'123'}>>>user{'Password':'123','ID': 1000,'name':'SCD'}
(2) D[key] = value
>>> user = { }>>> user['ID'] = 1000>>> user['name'] ='SCD'>>> user['Password'] ='123'>>>user{'Password':'123','ID': 1000,'name':'SCD'}>>>
(3) d = dict (Zip (key, value)), here key, value is the list
>>> key = ['ID','name','Password']>>> value = [1000,'SCD','123']>>> user =dict (Zip (key, value))>>>user{'Password':'123','ID': 1000,'name':'SCD'}>>>
The 2nd method of creating a dictionary is often used
2. Dictionary traversal
for inch User: ... Print " : " 123name:scd>>>
Often used is to create a dictionary of the form (2) and the traversal of the dictionary, about the other dictionary methods to continue to write tomorrow
Python Basic Knowledge---Dictionary