Dictionary
Key: Value pair
>>> wuang={' Zhang ': 1992, ' Chen ': 1990, ' Ren ': 1992}
>>> Wuang
{' Chen ': 1990, ' Ren ': 1992, ' Zhang ': 1992}
Add an Element
>>> wuang[' Wang ']=1992
>>> Wuang
{' Chen ': 1990, ' Ren ': 1992, ' Wang ': 1992, ' Zhang ': 1992}
Delete an element
>>> del wuang[' Ren ']
>>> Wuang
{' Chen ': 1990, ' Wang ': 1992, ' Zhang ': 1992}
Display Key Name
>>> Wuang.keys ()
[' Chen ', ' Wang ', ' Zhang ']
Display Value Name
>>> wuang.values ()
[1990, 1992, 1992]
Determine if an element exists in a dictionary
>>> ' Ren ' in Wuang
False
>>> ' Wang ' in Wuang
True
Use the Dict () function to create a dictionary
>>> dict ([' Zhang ', 165), (' Chen ', "(' Ren ', 163)])
{' Chen ':, ' ren ': 163, ' Zhang ': 165}
This article is from the "Don't Ang" blog, please be sure to keep this source http://wuang.blog.51cto.com/9559762/1604660
Python the next day (dictionary)