>>> person = {'sex' : 'female', 'age': 30, 'name' : 'mina'}
>>> print(person)
>>> print(type(person))
{'sex': 'female', 'age': 30, 'name': 'mina'}
<class 'dict'>
>>> person['sex']
female
person['age']
30
>>> myongji_hs = {}
>>> type(myongji_hs)
>>> myongji_hs['name'] = 'hong'
>>> print(myongji_hs)
{'name': 'hong'}
>>> myongji_hs['scholol_year'] = 5
>>> print(myongji_hs)
{'name': 'hong', 'scholol_year': 5}
>>> myongji_hs['class_no'] = 10
>>> print(myongji_hs)
{'name': 'hong', 'scholol_year': 5, 'class_no': 10}
>>> del myongji_hs['scholol_year']
>>> print(myongji_hs)
3]
{'name': 'hong', 'class_no': 10}
>>> results = {'A': 99, 'B': 91, 'C': 83, 'D': 100}
>>> type(results)
dict
>>> results['c']
83
>>> name3 = {'name': ['A', 'B', 'C']}
>>> print(name3)
{'name': ['A', 'B', 'C']}
- keys 함수
: 전체 item 중 key에 해당하는 부분만 따로 모아 list 타입으로 만들어주는 함수.>>> a = {'gender': 'Female', 'age' : 30, 'name': 'Kristian'} # a 딕셔너리의 keys만 출력합니다. >>> list(a.keys()) ['gender', 'age', 'name']
- value 함수
: ㅇㄹㄴㄹㄴㅇ>>> list(a.values()) ['Female', 30, 'Kristian']
- item 함수
>>> a.items() dict_items([('gender', 'Female'), ('age', 30), ('name', 'Kristian')])
- clear 함수
: 모든 항목(item) 삭제>>> a.clear() >>> print(a) {}
- get 함수
: value 출력>>> a = {'gender': 'Female', 'age' : 30, 'name': 'Kristian'} >>> a.get('gender') Female
- 변수에 key 확인
>>> 'gender' in a True >>>'weight' in a #없는 key False
>>> ds = {}
>>> type(ds)
>>> icecream = {'메로나': 1000, '폴라포': 1200, '빵빠레': 1800}
>>> print(icecream)
{'메로나': 1000, '폴라포': 1200, '빵빠레': 1800}
>>> icecream ['죠스바'] = 1200
>>> icecream['월드콘'] = 1500
>>> print(icecream)
{'메로나': 1000, '폴라포': 1200, '빵빠레': 1800, '죠스바': 1200, '월드콘': 1500}
>>> name = '메로나'
>>> print(f'{name} 가격:' , icecream[name])
메로나 가격: 1000
>>> icecream['메로나'] = 1200
>>> print(icecream)
{'폴라포': 1200, '빵빠레': 1800, '죠스바': 1200, '월드콘': 1500, '메로나': 1200}
>>> icecream.pop('메로나')
>>> print(icecream)
{'폴라포': 1200, '빵빠레': 1800, '죠스바': 1200, '월드콘': 1500}
>>> inventory = {'메로나': [300, 20], '비비빅': [400, 3], '죠스바': [250, 100]}
>>> print(inventory['메로나'] [0], '원')
300원
>>> print(inventory['메로나'] [1], '개')
20개
>>> inventory['월드콘'] = [500, 7]
>>> print(inventory)
{'메로나': [300, 20], '비비빅': [400, 3], '죠스바': [250, 100], '월드콘': [500, 7]}
https://colab.research.google.com/drive/1xg0SpT8_7cbhGCjsGXHlgrep3jdEOCrA?usp=sharing