[Python] Dictionary

REi·2024년 9월 3일

Python

목록 보기
7/8

> 딕셔너리 (Dictionary)

  • key:value 구조
dic = {1:"Python", 2:"Java", 3:"C"}

> 딕셔너리 특징

  • 키값으로 접근할 수 있음.
print(dic[3])

> 딕셔너리 데이터 추가

  • 방법 1 ) dict[key] = value
dic[4] = "Solidity"
  • 방법 2 ) update()
dic.update({5:"Javascript",6:"HTML"})

> 딕셔너리 데이터 삭제

  • del 키워드와 key값
del dic[4]

> keys()

  • 딕셔너리 key값만 출력

> values()

  • 딕셔너리 value값만 출력

> [추가] list()

  • list형으로 변환
  • 딕셔너리 -> 리스트 변환 가능
print("====Key List====")
dic_key_list = list(dic.keys())
print(dic_key_list)

print("====Value List====")
dic_value_list = list(dic.values())
print(dic_value_list)

0개의 댓글