[Python] 리스트에 특정 값이 있는지 체크하기

2021. 1. 5. 11:12Programming Language/Python

리스트에 특정 값이 있는지 체크

list = ['apple', 'banana', 'cherry']
if 'apple' in list:
print("리스트에 'apple'이 있습니다.")
if 'watermelon' not in list:
print("리스트에 'watermelon'이 없습니다.")

결과
리스트에 'apple'이 있습니다.
리스트에 'watermelon'이 없습니다.

반응형

'Programming Language > Python' 카테고리의 다른 글