Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- R
- SQL
- Numpy
- oracle
- Oracel
- sklearn
- level 1
- Kaggle
- pandas
- python3
- Python
- level 2
- 데이터 분석
- 카카오
- 알고리즘
- matplotlib
- 오라클
- 코딩테스트
- 파이썬
- 빅데이터 분석 기사
- 프로그래머스
- 실습
- 튜닝
- 머신러닝
- seaborn
- 빅분기
- 실기
Archives
- Today
- Total
라일락 꽃이 피는 날
[Python] 반복문 본문
728x90
for 반복문
반복 횟수가 정해져 있는 경우
for 변수명 in range(반복횟수):
수행 코드
for x in range(10):
print('반복 출력')

for x in range(10):
print('{}번째 반복'.format(x))

for char in 'abcde':
print(char)

for tup in (1, 2, 3, 4, 5):
print(tup)

enumerate
순서가 있는 자료형을 입력으로 받아 인덱스 값을 포함하는 enumerate 객체를 돌려준다.
seasons = ['Spring', 'Summer', 'Fall', 'Winter']
for i, name in enumerate(seasons):
print(i, name)

중첩 반복
for x in range(3): # main
for y in range(5): # sub → 3번 반복
수행 코드 # 15번 반복
수행 코드 # 3번 반복
while 반복문
반복의 조건이 있는 경우
조건식 : True → 반복
조건식 : False → 반복 중단
x = 0
while x < 3:
print(x)
x = x + 1

break : 반복의 종료
x = 0
while True:
if x == 5:
break
print(x)
x = x + 1

continue : 반복의 처음으로 이동
x = 0
while True:
if x == 3:
continue
print(x)
x = x + 1

728x90
'프로그래밍 > Python' 카테고리의 다른 글
| [Python] list (리스트) (0) | 2021.05.30 |
|---|---|
| [Python] tuple (튜플) (0) | 2021.05.30 |
| [Python] 조건문 (0) | 2021.05.21 |
| [Python] random (0) | 2021.05.21 |
| [Python] 연산자 (0) | 2021.04.23 |