์ฌ๊ธฐ์ ์ง์ ๋ ํ์๋ผ๋ ๊ฒ์ ๋ฐ๋ณต ๋์์ ํฌ๊ธฐ๊ฐ ๋๋ค.
List, Tuple, string, ...
L = [1,2,3]
for i in L :
print(i)
coffees = ['์๋ฉ๋ฆฌ์นด๋
ธ', '์นดํ๋ผ๋ผ', '์นดํ๋ชจ์นด', '๋ฐ๋๋ผ๋ผ๋ผ', 'ํธ๋๋๋ฆฝ', '์ฝ๋๋ธ๋ฃจ']
for coffee in coffees :
print(coffee)
for๋ฌธ์ ํน์ ํ์๋์ ๋ฐ๋ณต์ ํ๊ธฐ ๋๋ฌธ์, ํ์๋ฅผ ์๋์ผ๋ก ๋ง๋ค์ด์ฃผ๋ ๊ธฐ๋ฅ์ด ์์ผ๋ฉด ์ข๋ค.
ํ์ด์ฌ์์ ๊ธฐ๋ณธ์ ์ผ๋ก ์ ๊ณตํ๋ range ํจ์๋ ํน์ ์ซ์ ๋ฒ์๋ด์ ๊ฐ๋ค์ ์๋์ผ๋ก ์์ฑํด์ฃผ๋ ํจ์์ด๋ค.
e.g. range(1, 5)๋ 1, 2, 3, 4๋ฅผ ์ฐจ๋ก๋๋ก ์์ฑํด์ค๋ค. (5๋ ๋ฒ์์์ ์ ์ธ๋๋ค. ์ฆ, ๋ง์ง๋ง ์ซ์๋ ์ ์ธ๋๋ค. 1 <= x < 5)
# range ํจ์๋ฅผ ์ด์ฉํ ๊ตฌ๊ตฌ๋จ
for i in range(1,10) :
print(f"{i}๋จ")
for j in range(1,10) :
print(f"{i} X {j} = {i*j}")
print(" ")
# index๋ฅผ ํ์ฉํ ๋ฐฉ๋ฒ
for i in range(6) :
if prices[i] <= 5000 :
print(coffees[i])
# enumerete ํจ์๋ฅผ ํ์ฉํ ๋ฐฉ๋ฒ
for i, price in enumerate(prices) :
if price <= 5000 :
print(coffees[i])
# zip ํจ์๋ฅผ ํ์ฉํ ๋ฐฉ๋ฒ
for coffee, price in zip(coffees, prices) :
if price <= 5000:
print(coffee)
coffees = ['์๋ฉ๋ฆฌ์นด๋
ธ', '์นดํ๋ผ๋ผ', '์นดํ๋ชจ์นด', '๋ฐ๋๋ผ๋ผ๋ผ', 'ํธ๋๋๋ฆฝ', '์ฝ๋๋ธ๋ฃจ']
prices = [4100, 4600, 4600, 5100, 6000, 5000]
# ์ฒซ๋ฒ์งธ ๋ฐฉ๋ฒ
for i, price in enumerate(prices) :
if price <= 5500 :
print(coffees[i])
# ๋๋ฒ์งธ ๋ฐฉ๋ฒ
for i, price in enumerate(prices) :
if price - 500 <= 5000 :
print(coffees[i])