Python - 문제 미리보기
문제 1877
hard
다음 코드들의 실행 결과를 예측하시오:
```python
# Code A
text1 = " Python Programming "
result1 = text1.strip().upper()
# Code B
text2 = "Hello-World-Python"
result2 = text2.replace("-", " ").split()
# Code C
text3 = "apple,banana,,cherry,"
result3 = text3.split(",")
print("A:", result1)
print("B:", result2)
print("C:", result3)
```
정답: B
⦁ 각 코드의 상세 분석:
Code A: 메서드 체이닝
```python
text1 = " Python Programming "
# 1단계: text1.strip() → "Python Programming"
# 2단계: .upper() → "PYTHON PROGRAMMING"
result1 = "PYTHON PROGRAMMING"
```
Code B: 교체 후 분할
```python
text2 = "Hello-World-Python"
# 1단계: text2.replace("-", " ") → "Hello World Python"
# 2단계: .split() → ["Hello", "World", "Python"]
result2 = ["Hello", "World", "Python"]
```
Code C: 빈 요소를 포함한 분할
```python
text3 = "apple,banana,,cherry,"
# 쉼표로 분할 → ["apple", "banana", "", "cherry", ""]
# 연속된 쉼표는 빈 문자열을 생성
# 마지막 쉼표도 빈 문자열을 생성
result3 = ["apple", "banana", "", "cherry", ""]
```
💡 학습 팁
이 문제를 포함한 Python 과목의 모든 문제를 순차적으로 풀어보세요. 진행상황이 자동으로 저장되어 언제든지 이어서 학습할 수 있습니다.