• 회원가입
  • 로그인
  • 구글아이디로 로그인

[keyword] Python - break 키워드 - 반복문 탈출. (=loop 빠져나오기 = break키워드 = 브레이크키워드)

5471  
목차
  1. break 예제 - for 반복문 탈출
  2. break 정의
  3. break 예제 - while 반복문 탈출

 

break 예제 - for 반복문 탈출

[예제1]

 

for i in range(5):

    if i > 2:

        break

    print(i, end=' ')

 

결과값: 0 1 2 

※ print 구문이 break 구문보다 뒤에 위치해 2까지만 출력.

 

break 정의

 

(for/while) 반복문 탈출. (= loop 빠져나오기)

※ 주의: 출력문 위치에 따라 출력 결과 달라짐.

 


cf.

  • continue 키워드 : 특정 조건일 때만 건너뛰고, 다음 조건 계속 실행.
  • pass 키워드 : 아무 작업 안 함. 단지, 들여쓰기 문법 맞춤용.

 

 

break 예제 - while 반복문 탈출

 

i = 0

while i < 5:

    print(i, end=' ')

    if i == 3:

        break

    i += 1

 

결과값: 0 1 2 3 

※ priint 구문이 break 앞에 위치해서 3까지 출력.


분류 제목
numpy PY - NumPy ufuncs : Simple Arithmetic (간단 산수)
numpy PY - NumPy ufuncs : Rounding Decimals (반올림 소수점)
numpy PY - NumPy ufuncs : Logs (로그)
numpy PY - NumPy ufuncs : Summations (합계=합산)
numpy PY - NumPy ufuncs : Products (요소 곱셈)
numpy PY - NumPy ufuncs : Differences (요소의 차)
numpy PY - NumPy ufuncs : Finding LCM (최소공배수 찾기)
numpy PY - NumPy ufuncs : Finding GCD (최대공약수 찾기)
numpy PY - NumPy ufuncs : Trigonometric Functions (삼각함수)
numpy PY - NumPy ufuncs : Hyperbolic Functions (쌍곡선함수)
numpy PY - NumPy ufuncs : Set Operations (집합 연산)
howto Python - 3과 5의 배수의 합산(합계)
basic Python - Math (수학)
module Python - statistics 모듈 메서드 종류 (= 통계 모듈)
module Python - statistics.harmonic_mean() 메서드 - 조화 평균값 (= harmonic…
module Python - statistics.mean() 메서드 ★ - 평균값 (= mean메서드 = 민메서드)
module Python - statistics.median() 메서드 ★ - 중앙값 (= 중간값 = 가운데값 = med…
module Python - statistics.median_grouped() 메서드 -
module Python - statistics.median_high() 메서드 - 높은 중앙값 (= median_hig…
module Python - statistics.median_low() 메서드 - 낮은 중앙값 (= median_low메…
18/24
목록
찾아주셔서 감사합니다. Since 2012