Here is a small series to bring you a Python operation dictionary type of common methods (recommended). Small series feel very good, now share to everyone, also give us a reference, follow the small series come and see it
The Has_key () method checks to see if the dictionary contains the specified key, and returns true if any, otherwise false.
Syntax format:
Dictionary_name.has_key (key) Dict1 = {' hexh ': ' yangry ', ' ' in ': ' Weild ', ' The ' ': ', ', ', ' [] ': ' HUANGMG '}print dict1.has_key (' Print Dict1.has_key (' #resultTrueFalse ')
2.clear () method
Used to clear all items in the dictionary without a return value.
How to use:
Dictionary_name.clear ()
3,copy method
The copy () method returns a new dictionary with the same key-value pair, in the following format:
Dictionary_targetname = Dictionary_sourcenme.copy ()
4,fromkeys () method
Use the given key to create a new dictionary with a value of none for each key value.
Dictionary_name.fromkeys ([Key1,key2,...], (default_value))
5,update () method
Format:
Update_dictionary.update (source_dictionary) Mydict1 = {' 1 ': ' Yy11 ', ' 2 ': ' Yy22 ', ' 3 ': ' yy33 '}newdict = {' 2 ': ' Success '} Mydict1.update (newdict) print Mydict1 #result {' 1 ': ' Yy11 ', ' 3 ': ' Yy33 ', ' 2 ': ' Success '}
Above this Python operation dictionary type of common methods (recommended) is small to share all the content of everyone, hope to give you a reference, but also hope that we support topic.alibabacloud.com.