반응형
# Dictionary is save each data using by pair of key and value
# Make dictionary type object using by '{' or '}' keyword
current_price = {}
# Check data type using 'type()' function.
print(type(current_price))
# Add new item with key
current_price['naver'] = 1
# Check result
print(current_price)
# Add another item with key
current_price['DaumKAKAO'] = 2
# Check result
print(current_price)
# Length of dictionary object
print(len(current_price))
# Dictionary type object is not support indexing.
# print(current_price[0])
# Extract specific item using by key
print(current_price['DaumKAKAO'])
실행 결과
$ py dictionary.py
<class 'dict'>
{'naver': 1}
{'naver': 1, 'DaumKAKAO': 2}
2
2
반응형
'Programming > Python' 카테고리의 다른 글
[Python-Basic] List Data Type - 3 (Index) (0) | 2019.11.05 |
---|---|
[Python-Basic] List Data Type - 2 (Generate) (0) | 2019.11.05 |
[Python-Basic] List Data Type - 1(Add) (0) | 2019.11.05 |
[Python-Basic] Dictionary Data Type - 2 (0) | 2019.11.05 |
[Python-Basic] Dictionary Data Type - 1 (0) | 2019.11.05 |