Python - 문제 미리보기

문제 1842

medium
리스트 언패킹(Unpacking)에서 빈칸에 들어갈 올바른 코드는?
```python
fruits = ["apple", "banana", "cherry"]
_____, _____, _____ = fruits
print(x)
print(y)
print(z)
```
A. `x`, `y`, `z`
B. `fruits[0]`, `fruits[1]`, `fruits[2]`
C. `"x"`, `"y"`, `"z"`
D. `[x]`, `[y]`, `[z]`

정답: A



⦁ 리스트 언패킹(List Unpacking):
```python
fruits = ["apple", "banana", "cherry"]
x, y, z = fruits
```
⦁ 언패킹 과정:
⦁ fruits[0] → x (`"apple"`)
⦁ fruits[1] → y (`"banana"`)
⦁ fruits[2] → z (`"cherry"`)

⦁ 실행 결과:
```txt
apple
banana
cherry
```
⦁ 언패킹 가능한 자료구조:
```python
# 리스트
colors = ["red", "green", "blue"]
r, g, b = colors

# 튜플
coordinates = (10, 20)
x, y = coordinates

# 문자열
letters = "ABC"
a, b, c = letters

# 집합 (순서 보장 안됨)
numbers = {1, 2, 3}
x, y, z = numbers # 순서는 예측 불가
```

💡 학습 팁

이 문제를 포함한 Python 과목의 모든 문제를 순차적으로 풀어보세요. 진행상황이 자동으로 저장되어 언제든지 이어서 학습할 수 있습니다.