반응형
for i in range(5): # for each number i in range 0-4. range(5) function returns list [0, 1, 2, 3, 4]
print(i) # this line is executed 5 times. First time i equals 0, then 1, ...
primes = [2, 3, 5, 7] # create new list
for prime in primes:
print(prime)
# Print each prime number from the "primes" list using the "for" loop.
# A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
산출물 (Output)
0
1
2
3
4
2
3
5
7
* "For" loops는 주어진 순서 대로 반복하는데 사용됩니다.
각 반복마다, "for" loop 안에 정의된 변수는 목록 안의 다음 값에 대하여 할당될 것입니다.
반응형
'Python 배우기' 카테고리의 다른 글
while_loop.py (0) | 2016.03.10 |
---|---|
for_string.py (0) | 2016.03.09 |
else_elif.py (0) | 2016.03.09 |
if_statement.py (0) | 2016.03.08 |
boolean_order.py (0) | 2016.03.08 |
댓글