Day8 --- Python dictionary type and operation

Dictionary class

1. Generation:

    . A description:

      Dictionary is a collection of key-value pairs, key-value pair: the key is the data index extension

    . B generation method:  

Use} or {dict () 
= {A ' A ' =. 1, ' B ' = 2, ' C ' =. 3 } 
A = dict (A =. 1, B = 2, C =. 3 ) 
A = {} # can be used to generate an empty dictionary
Note that: {} generated default dictionary can not be used to generate a set of

2. dictionary class methods:

 
. 1  del   d [k]   # remove the key and the corresponding value 
2 k in d    # determines whether k is the d key 
. 3 d.key ()     # List all the key 
. 4 d.values ()   # list all value 
. 5 d.items ()    # List all the key and the corresponding value 
. 6 d.get (K, <default>)   # obtaining the key corresponding to the value, if the key does not exist <default> is returned 
. 7 d.pop ( K, <default>)   # obtain a value corresponding to the key and delete, if the key does not exist <default> is returned 
. 8 d.popitem () returns a tuple   # remove the last key-value pair dict

 

Guess you like

Origin www.cnblogs.com/love-coding/p/11409462.html