(Python 2-3๊ฐ) Conditionals and Loops
210802
์กฐ๊ฑด๋ฌธ
If - elif - else
condition
if <์กฐ๊ฑด>: # if๋ฅผ ์ฐ๊ณ ์กฐ๊ฑด ์ฝ์
ํ โ:โ ์
๋ ฅ
<์ํ ๋ช
๋ น1-1> # ๋ค์ฌ์ฐ๊ธฐ(indentation)ํ ์ํ๋ช
๋ น ์
๋ ฅ
<์ํ ๋ช
๋ น1-2> # ๊ฐ์ ์กฐ๊ฑดํ์ ์คํ์ผ ๊ฒฝ์ฐ ๋ค์ฌ์ฐ๊ธฐ ์ ์ง
elif <์กฐ๊ฑด>
elif <์กฐ๊ฑด>: # if๋ฅผ ์ฐ๊ณ ์กฐ๊ฑด ์ฝ์
ํ โ:โ ์
๋ ฅ
<์ํ ๋ช
๋ น2-1> # ๋ค์ฌ์ฐ๊ธฐ(indentation)ํ ์ํ๋ช
๋ น ์
๋ ฅ
<์ํ ๋ช
๋ น2-2> # ๊ฐ์ ์กฐ๊ฑดํ์ ์คํ์ผ ๊ฒฝ์ฐ ๋ค์ฌ์ฐ๊ธฐ ์ ์ง
else: # ์กฐ๊ฑด์ด ๋ถ์ผ์นํ ๊ฒฝ์ฐ ์ํํ ๋ช
๋ น block
<์ํ ๋ช
๋ น3-1> # ์กฐ๊ฑด ๋ถ์ผ์น ์ ์ํํ ๋ช
๋ น ์
๋ ฅ
<์ํ ๋ช
๋ น3-2> # ์กฐ๊ฑด ๋ถ์ผ์น ์ ์ํํ ๋ช
๋ น ๋ค์ฌ์ฐ๊ธฐ ์ ์ง๋ฐ๋ณต๋ฌธ
๋๋ฒ๊น
Previous(Python 2-4๊ฐ) String and advanced function conceptNext(Python 2-2๊ฐ) Function and Console I/O
Last updated