본문 바로가기
Python/기본

[Python] dictionary

by 카피마스터 2024. 10. 5.

선언

my_dic1 = dict()
my_dic2 = {}

 

아이템 등록

my_dic1['사과'] = 3

 

검색

find_value = my_dic1.get('사과')
if find_value == None:
    print("찾을수 없음")
else:
    print("Value is {VALUE}".format(VALUE=find_value))

 

for

# dictionary를 돌면서 key - value를 얻는다
for item in my_dic1.items():
    print( "ITEM : {KEY} - {VALUE}".format(KEY=item[0], VALUE=item[1]) )

 

'Python > 기본' 카테고리의 다른 글

[Python] Mac에 Python 설치  (0) 2024.10.27
[Python] 상수 사용  (0) 2024.10.07
[Python] 키워드  (0) 2024.10.05
[Python] 내장 함수  (0) 2024.10.05
[Python] String  (1) 2024.09.15