본문 바로가기

IT/Python

[파이썬] if, elif, else 구문

파이썬에는 if(만약에) 관련 3가지 구문이 있다.

if(만약에), elif(만약에2~), else(그 나머지는)

예시는 아래와 같다.

weather = input("Enter weather (sunny, rainy, snowy): ")

if weather.lower() == "sunny":

print("Wear a t-shirt")

#해가뜨는 날이면 t-Shirt를 입어라

elif weather.lower() == "rainy":

print("Bring an umbrella and boots")

#비가오는 날이면, 우산과 부츠를 가져가라

elif weather.lower() == "snowy":

print("Wear a warm coat and hat")

#눈이 오는 날이면, 코트와 모자를 가지고 가라

else:

print("Sorry, not sure what to suggest for", weather)

#그 나머지 날씨에는 추천 해 줄 것이 없다

'IT > Python' 카테고리의 다른 글

[파이썬] Slicing (자르기)  (0) 2020.06.29
[파이썬] Casting/캐스팅  (0) 2020.06.29
[파이썬] Boolean string methods (Yes or No)  (0) 2020.06.29
[파이썬] Pandas Cheat Sheet  (0) 2020.06.17
[파이썬] Model Development (Residual Plot)  (0) 2020.06.16