(파이썬) loops
2022. 11. 29. 22:20ㆍ파이썬
728x90
#1
range(start,stop,step)
//step 인자가 생략되면 디폴트 값 1 적용, step이 0이면 에러
//start 인자가 생략되면 디폴트 값 0 적용
//stop 인자는 포함하지 않음 ex) for x in range(5) 라면 0,1,2,3,4 까지만 출력
#2
else문이 while문과 for문에도 쓸 수 있다.
count=0
while(count<5):
print(count)
count +=1
else:
print("count value reached %d" %(count))
for i in range(1, 10):
if(i%5==0):
break
print(i)
else:
print("this is not printed because for loop is terminated because of break but not due to fail in condition")
반복문조건에 해당하지 않으면 else문으로 가서 종료
*break문이 있으면 else문도 건너뛰어서 완전 빠져나감
*continue문이 있어도 else문 실행
728x90
'파이썬' 카테고리의 다른 글
| (파이썬) Dictionaries (0) | 2022.11.30 |
|---|---|
| (파이썬) class and function (0) | 2022.11.30 |
| (파이썬) conditions (0) | 2022.11.29 |
| (파이썬) String Operation (0) | 2022.11.23 |
| (파이썬) String Formatting (2) | 2022.11.23 |