for λ°λ³΅λ¬Έκ³Ό 리μ€νΈ ν¨κ» μ¬μ©νκΈ°
νμ΄μ¬μ for λ°λ³΅λ¬Έμ 리μ€νΈμ ν¨κ» μ¬μ©νλ©΄ 리μ€νΈμ κ° μμλ₯Ό μμ°¨μ μΌλ‘ μ²λ¦¬ν μ μμ΅λλ€.
for λ°λ³΅λ¬Έκ³Ό 리μ€νΈμ μ¬μ©
for λ°λ³΅λ¬Έμ 리μ€νΈμ κ° μμμ μ κ·Όνκ³ , μ΄ μμλ€μ νμ©ν΄ λ€μν μ°μ°μ΄λ μμ μ μνν μ μμ΅λλ€.
for λ°λ³΅λ¬Έκ³Ό 리μ€νΈμ μ¬μ©
# μ«μ 리μ€νΈ μμ± numbers = [1, 2, 3, 4, 5] # κ²°κ³Όλ₯Ό μ μ₯ν λΉ λ¦¬μ€νΈ squared_numbers = [] # 'for' λ°λ³΅λ¬Έμ μ¬μ©νμ¬ κ° μ«μμ μ κ³±μ κ³μ°νκ³ κ²°κ³Ό 리μ€νΈμ μΆκ° for number in numbers: squared = number ** 2 # μ κ³± κ³μ° squared_numbers.append(squared) # κ³μ°λ κ°μ 리μ€νΈμ μΆκ° # κ²°κ³Ό μΆλ ₯ print("Original Numbers:", numbers) # μλ³Έ 리μ€νΈ [1, 2, 3, 4, 5] print("Squared Numbers:", squared_numbers) # μ κ³± κ³μ° κ²°κ³Ό [1, 4, 9, 16, 25]
Guidelines
AI Tutor
Publish
Design
Upload
Notes
Favorites
Help
Code Editor
Run
Generate
Execution Result