원문 : http://learnpythonthehardway.org/book/ex33.html
for 루프에대해서 알아봤으니 이제 while 루프에 대해서 알아보자 (ex33.py)
i = 0
numbers = []
while i < 6:
print "At the top i is %d" % i
numbers.append(i)
i = i + 1
print "Numbers now: ", numbers
print "At the bottom i is %d" % i
print "The numbers: "
for num in numbers:
print num
결과
알 수 있는 내용
1. while 문의 기본 사용법은 "while 조건식:" 이다.
- 조건식이 ture 일 때 (false 판정이 나면 while 문 종료) 블록 안의 코드를 실행 한다.
반응형
'Python > Python 어렵게 배우기' 카테고리의 다른 글
| Python 어렵게 배우기 - Exercise 35: Branches and Functions (0) | 2014.01.02 |
|---|---|
| Python 어렵게 배우기 - Exercise 34: Accessing Elements of Lists (0) | 2013.12.30 |
| Python 어렵게 배우기 - Exercise 32: Loops and Lists (0) | 2013.12.27 |
| Python 어렵게 배우기 - Exercise 31: Making Decisions (0) | 2013.12.26 |
| Python 어렵게 배우기 - Exercise 30: Else and If (0) | 2013.12.26 |