Python - 문제 미리보기
문제 1928
medium
다음 코드의 실행 결과는?
```python
fruits = ["apple", "banana", "cherry", "avocado", "grape"]
result = [fruit for fruit in fruits if "a" in fruit]
print(result)
```
```python
fruits = ["apple", "banana", "cherry", "avocado", "grape"]
result = [fruit for fruit in fruits if "a" in fruit]
print(result)
```
정답: B
⦁ 문자열에 특정 글자가 포함된 요소만 필터링
⦁ `"a" in fruit`: 과일 이름에 "a"가 포함되어 있는지 확인
⦁ 대소문자를 구분함 (소문자 "a"만 검사)
비슷한 활용 예시:
```python
# 특정 문자로 시작하는 단어
[word for word in words if word.startswith("p")]
# 특정 문자로 끝나는 단어
[word for word in words if word.endswith("ing")]
# 길이가 특정 조건인 단어
[word for word in words if len(word) > 5]
```
💡 학습 팁
이 문제를 포함한 Python 과목의 모든 문제를 순차적으로 풀어보세요. 진행상황이 자동으로 저장되어 언제든지 이어서 학습할 수 있습니다.