Ex.
``` my_dic = {} my_dic = dict() my_dic = {'a':111, 'b':222, 'c':333, 'd':444} ```
By using 'in' function, you can check if the key value is in that dictionaryEx.
``` pro_dic = { 'name' : 'DRAM', 'capa' : '32g', 'maker' : 'SK', 'price' : 320000 } print(pro_dic.get('name')) # get(key) print(pro_dic['name']) # dict[key] ```
Ex.
``` print('maker' in pro_dic) # True print('price' in pro_dic) # True print('ssn' in pro_dic) # False ```
Ex.
``` pro_dic['ssn'] = 1234 print(pro_dic) #################################################### add_info = { 'loc': '이천', 'pop': 33 } pro_dic.update(add_info) print(pro_dic) ```
ㄴ> 출력 값
``` {'name': 'DRAM', 'capa': '32g', 'maker': 'SK', 'price': 320000, 'ssn': 1234} {'name': 'DRAM', 'capa': '32g', 'maker': 'SK', 'price': 320000, 'ssn': 1234, 'loc': '이천', 'pop': 33} ```
Ex.
``` pro_dic[price] = 230000 print(pro_dic) ```
ㄴ> 출력 값
``` {'name': 'DRAM', 'capa': '32g', 'maker': 'SK', 'price': 230000, 'ssn': 1234, 'loc': '이천', 'pop': 33} ```
Ex.
``` del pro_dic['loc'] pro_dic.pop('pop') pro_dic.clear() ```
Ex.
``` my_dic = { 'name': 'James', 'age': 34, 'address': 'Texas', 'phone': '123456' } my_keys = my_dic.keys() my_keys = list(my_keys) print(my_keys) # my_values = my_dic.values() my_values = list(my_values) print(my_values) # my_items = my_dic.items() my_items = list(my_items) print(my_items) ```
ㄴ> 출력값
``` ['name', 'age', 'address', 'phone'] ['James', 34, 'Texas', '123456'] [('name', 'James'), ('age', 34), ('address', 'Texas'), ('phone', '123456')] ```