Python While반복문
2022. 12. 15. 13:07ㆍPython
i = 0
a = [1, 2, 3, 4]
s = 3
# while문 이용
while i < len(a):
if a[i] == s:
print(s, 'found in list')
break
i += 1
else:
print(s, 'not found in list')
# for문 이용
for p in a:
if s == p:
print(s, 'found in list')
break
else:
print(s, 'not found in list')
# d, c, b, a -> LIFO
list1 = ['a', 'b', 'c', 'd']
while list1:
print(list1.pop())
'Python' 카테고리의 다른 글
Python 예외처리 (0) | 2022.12.16 |
---|---|
Python 함수(1) (0) | 2022.12.15 |
Python for반복문 (0) | 2022.12.15 |