[ ํํ์ for ์์ in ๋ฐ๋ณต๊ฐ๋ฅํ ๊ฐ์ฒด ]
[ ํํ์ for ์์ in ๋ฐ๋ณต๊ฐ๋ฅํ ๊ฐ์ฒด if๋ฌธ]
๋น list๋ฅผ ์์ฑ ํ for๋ฌธ์ ๋๋ ค append()
result = []
for num in range(1,11):
result.append(num)
print(result)
# output
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# ์กฐ๊ฑด์ด ์๋ ํํ์์ผ ๊ฒฝ์ฐ
result = []
for num in range(1,11):
if num > 5:
result.append(num)
print(result)
# output
[6, 7, 8, 9, 10]
result = [ num for num in range(1,11) ]
print(result)
# output
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# ์กฐ๊ฑด์ด ์๋ ํํ์์ผ ๊ฒฝ์ฐ
result = [ num for num in range(1,11) if num > 5 ]
print(result)
# output
[6, 7, 8, 9, 10]