프로그래밍/python
Python의 포함 연산자 in, not in
이휘재123
2023. 7. 3. 18:02
반응형
문자열, 배열, 튜플, 딕셔너리에 사용할 수 있다.
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
반응형