반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- string
- google apps script
- Google Spreadsheet
- Github
- Google Excel
- 파이썬
- Redshift
- dataframe
- Java
- Tkinter
- Excel
- GIT
- PostgreSQL
- Mac
- hive
- PANDAS
- Kotlin
- PySpark
- math
- list
- numpy
- matplotlib
- gas
- Python
- django
- array
- SQL
- Apache
- c#
Archives
- Today
- Total
목록get method (1)
달나라 노트
Python Basic : get (dictionary에 존재하지 않는 key를 전달했을 때 발생하는 에러 해결. dictionary용 nvl)
dict_test = { 'a': 1, 'b': 2, 'c': 3, } sample_value = dict_test['d'] print(sample_value) -- Result KeyError: 'd' 위 코드를 실행시켜보면 KeyError가 발생합니다. 왜냐면 dict_test라는 dictionary에는 a, b, c라는 key가 존재하는데, 존재하지 않는 d라는 이름의 key를 전달했기 때문이죠. 위 예시에서처럼 간단한 dictionary를 사용하면 사실 KeyError가 발생할 일도 거의 없고, KeyError가 발생한다고 해도 금방 코드를 수정할 수 있습니다. 하지만 dictionary가 복잡해지고 경우에 따라 key의 종류가 변동될 수 있는 상황에서 dictionary의 key를 전달해야한다면..
Python/Python Basic
2022. 1. 5. 22:51