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

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

5481  
목차
  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 Searching Arrays (배열 검색) ★
numpy PY - NumPy Sorting Arrays (배열 정렬) - sort() 메서드 ★
numpy PY - NumPy Filter Array (배열 필터링) ★
numpy PY - NumPy Random : Numbers (난수 = 랜덤숫자)
numpy PY - NumPy Random : Data Distribution (랜덤 데이터 분포)
numpy PY - NumPy Random : Permutations (랜덤 순열)
numpy PY - NumPy Random : Seaborn (분포 시각화)
numpy PY - NumPy Random : Normal Distribution (정규 분포)
numpy PY - NumPy Random : Binomial Distribution (이항 분포)
numpy PY - NumPy Random : Poisson Distribution (푸아송 분포)
numpy PY - NumPy Random : Uniform Distribution (균등 분포)
numpy PY - NumPy Random : Logistic Distribution (로지스틱 분포)
numpy PY - NumPy Random : Multinomial Distribution (다항 분포)
numpy PY - NumPy Random : Exponential Distribution (지수 분포)
numpy PY - NumPy Random : Chi Square Distribution (카이제곱 분포)
numpy PY - NumPy Random : Rayleigh Distribution (레일리 분포)
numpy PY - NumPy Random : Pareto Distribution (파레토 분포)
numpy PY - NumPy Random : Zipf Distribution (지프 분포)
numpy Python - NumPy ufuncs : Intro (일반함수 소개)
numpy PY - NumPy ufuncs : Create Function (일반함수 생성)
17/24
목록
찾아주셔서 감사합니다. Since 2012