12.4 연습문제
-
9. 딕셔너리 만들기Python/Grammar 2022. 12. 2. 10:21
# 1. 딕셔너리 만들기 딕셔너리는 말 글대로 사전에서 단어를 찾듯이 키를 찾으면 값을 가져올 수 있다고 해서 딕셔너리라는 명칭이 붙었다. 딕셔너리를 만드는방법은 여러 가지가 있지만 가장 기본적인 방법으로 중괄호 안에 키: 값을 넣은 {키1: 값1, 키2: 값2, ...} 형태로 만든다. 각 키와 값은 콤마로 구분해주며, 키와 값은 1:1 대응되어 하나의 키에는 값을 하나만 지정할 수 있다. 따라서 키와 값을 "키-값 쌍(key-value pair)"이라고 부른다. 참고로 딕셔너리와 같은 키-값 쌍 형태의 자료형을 Hash, Hash Map, Hash Table 등으로 부르며 REDIS 저장기법 중 HSET의 H도 해시를 의미한다. 1-1. 빈 딕셔너리 만들기 : 빈 딕셔너리를 만들려면 중괄호 안에 아무..