[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' 카테고리의 다른 글

[Python] re.sub() 으로 문자열 치환  (0) 2021.01.05
[Python] collections.OrderedDict 정렬  (0) 2021.01.05
[Python] split()  (0) 2021.01.04
[Python] 정규 표현식  (0) 2021.01.04
[Python] isalnum(), isalpha() 함수  (0) 2021.01.04