Python - 문제 미리보기
문제 2000
easy
다음 코드에서 빈칸에 들어갈 적절한 메소드는?
```python
settings = {
"theme": "dark",
"language": "English",
"notifications": True
}
settings._____({"theme": "light", "auto_save": True})
print(settings["theme"])
print("auto_save" in settings)
```
```python
settings = {
"theme": "dark",
"language": "English",
"notifications": True
}
settings._____({"theme": "light", "auto_save": True})
print(settings["theme"])
print("auto_save" in settings)
```
정답: C
⦁ `update()` 메소드: 여러 키-값 쌍을 한 번에 수정/추가
⦁ 딕셔너리나 키-값 쌍 이터러블을 매개변수로 받음
⦁ 기존 키는 값을 수정, 새로운 키는 추가
`update()` 동작 과정:
1. 초기: `{"theme": "dark", "language": "English", "notifications": True}`
2. `{"theme": "light", "auto_save": True}` 적용
3. "theme": "dark" → "light" (기존 키 수정)
4. "auto_save": True (새로운 키 추가)
5. 최종: `{"theme": "light", "language": "English", "notifications": True, "auto_save": True}`
실행 결과:
⦁ `settings["theme"]` → "light"
⦁ `"auto_save" in settings` → True
💡 학습 팁
이 문제를 포함한 Python 과목의 모든 문제를 순차적으로 풀어보세요. 진행상황이 자동으로 저장되어 언제든지 이어서 학습할 수 있습니다.