Python - 문제 미리보기

문제 1876

medium
`split()` 메서드의 실행 결과로 올바른 것은? ```python text = "apple,banana,cherry" result = text.split(",") print(result) ```
A. `"apple banana cherry"`
B. `["apple", "banana", "cherry"]`
C. `("apple", "banana", "cherry")`
D. `{"apple", "banana", "cherry"}`

정답: B

⦁ `split()` 메서드의 특징: ⦁ 리스트 반환: 분할된 문자열들을 리스트로 반환 ⦁ 구분자 기준: 지정된 구분자를 기준으로 문자열 분할 ⦁ 구분자 제거: 구분자는 결과에서 제거됨 ⦁ 분할 과정 분석: ```python text = "apple,banana,cherry" # 쉼표(,)를 기준으로 분할 # 결과: ["apple", "banana", "cherry"] ``` ⦁ 다양한 구분자 사용: ```python # 쉼표로 분할 text1 = "a,b,c" print(text1.split(",")) # ['a', 'b', 'c'] # 공백으로 분할 text2 = "hello world python" print(text2.split(" ")) # ['hello', 'world', 'python'] print(text2.split()) # ['hello', 'world', 'python'] (기본값) # 다른 구분자들 text3 = "one|two|three" print(text3.split("|")) # ['one', 'two', 'three'] text4 = "apple-banana-cherry" print(text4.split("-")) # ['apple', 'banana', 'cherry'] ```

💡 학습 팁

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