티스토리 뷰
for 문에도 else 문이 있는지 처음 알았다. 충격...
for - else 구문은, for문 안에 있는 break 여부에 따라 갈린다.
break문을 만나지 않는다면, for문을 빠져나와 else 문으로 나온다.
break문을 만나지 않는다면, 반복문이 정상적으로 수행된 경우 else 블럭 실행
numbers = [1, 2, 3, 4, 5, 6]
예시 | 출력 |
numbers = [1, 2, 3, 4, 5, 6] for num in numbers: if num == 3: print(num) break else: print("pass") else : print("not found 3...") |
pass pass 3 |
numbers = [1, 2, 3, 4, 5, 6] for num in numbers: if num == 3: print(num) else: print("pass") else : print("not found 3...") |
pass pass 3 pass pass pass not found 3... |
numbers = [1, 2, 3, 4, 5, 6] for num in numbers: if num == 7: print(num) break else: print("pass") else : print("not found 3...") |
pass pass pass pass pass pass not found 3... |
'python' 카테고리의 다른 글
[python django] django 기초 (1) (0) | 2019.12.20 |
---|---|
[python] 데이터베이스 연동 SQLite3 삽입, 수정, 삭제, Dump, commit (0) | 2019.12.05 |
[python] *args, *kwargs, lambda, enumerate, type hint (0) | 2019.12.03 |
[python] list, tuple, dictionary, set (0) | 2019.12.02 |
python 가상환경 설정 (0) | 2019.12.02 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- UITableViewController Not Working
- Django
- django clean
- 까만 화면
- django tag
- CellForRowAt Not Called
- python 웹 배포
- django 로그인접근
- iOS UITableView 출력안됨
- 테이블출력안됨
- 알파벳 카운팅
- Realtime Database
- CellForRowAt 호출안됨
- iOS 화면 안나옴
- 장고 태그달기
- django 태그
- 장고 게시판
- 실시간 데이터베이스
- Firebase 데이터베이스 추천
- cleaned_data
- pythonanywhere배포방법
- django pythoneverywhere
- iOS 검은 화면
- django 게시판
- 웹 배포
- ModelForm Form 차이
- django 개발일지
- 데이터베이스 추천
- pythonanywhere배포
- iOS 데이터베이스
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
글 보관함