Take Python dictionary key, value pairs

1. Take keys: keys () method

# Spyder 
BB = { ' Talent / terrible ' : 23, ' Voldemort & Porter ' : ' Army ' , ' ha, personnel, Round ' : ' HHH ' }
 for II in bb.keys ():
     Print (II) 

# output: 
# talent / terrible 
# Voldemort & Porter 
# ha ha ha, talent, Round

2. values: values ​​() method

for jj in bb.values():
    print(jj)

#输出
#23
#army
#hhh

3. Take key-value pair: items () method

for kk, VV in bb.items ():
     Print (kk, VV) 

# output 
# talents / terrible 23 
# Voldemort & Porter Army 
# Ha ha ha, talent, round hhh

4. The individual keys

= xx bb.keys ()
 Print (xx) # Output: dict_keys ([ 'talent / horrible', 'Voldemort & Potter', 'Ha ha ha, talent, round']) 

IF  ' talent / horrible '  in bb.keys ():
     Print (BB [ ' talent / terrible ' ])
 # output value corresponding to the key: 23

 

Guess you like

Origin www.cnblogs.com/qi-yuan-008/p/11862905.html