반응형
문자열, 배열, 튜플, 딕셔너리에 사용할 수 있다.
1. 문자열(strings)
########### in ###########
if 'p' in 'python':
print(True)
else:
print(False)
-------------------------
True
########### not in ###########
if 'k' not in 'python':
print(True)
else:
print(False)
-------------------------
True
2. 리스트(list)
############## in ##############
if 'a' in ['a','b','c']:
print(True)
else:
print(False)
--------------------------------
True
############## not in ##############
if 'd' not in ['a','b','c']:
print(True)
else:
print(False)
--------------------------------
True
3. 튜플(tuple)
############# in #############
if 'a' in ('a','b','c'):
print(True)
else:
print(False)
-------------------------
True
############# not in #############
if 'd' not in ('a','b','c'):
print(True)
else:
print(False)
-------------------------
True
4. 딕셔너리(Dictionary)
########### in ###########
if 'a' in {'a':1,'b':2}:
print(True)
else:
print(False)
---------------------------
True
########### not in ###########
if 'c' not in {'a':1,'b':2}:
print(True)
else:
print(False)
---------------------------
False
[Python] 포함(Containment) 연산자 in, not in
파이썬에는 포함(Containment) 연산자를 ( in, not in ) 제공하며, 객체 in (not in) 시퀀스의 형태로 사용 가능하다. 1. 문자열(strings) ########### in ########### if 'p' in 'python': print(True) else: print(False) ---------------
pydole.tistory.com
반응형
'프로그래밍 > python' 카테고리의 다른 글
| 기존의 list의 값을 이용해서 새로운 list를 만드는 방법 list comprehension (0) | 2023.07.06 |
|---|---|
| python decorator (0) | 2023.07.05 |
| dict list를 key1을 기준으로 그룹화하고, 각 그룹에 속하는 key2들을 모으는 방법은 다음과 같습니다. (0) | 2023.06.26 |
| selenium webdriver 새 탭 간의 이동 (0) | 2023.06.23 |
| python pyinstaller exe file decomplie 과정 (0) | 2023.06.23 |