파이썬에서의 if 는 특정한 조건을 확인할 때 사용되며 if 문의 구조는 다음과 같다.
if expression:
codes to execute
산출되는 값이 True 이면 Codes to execute 부분의 코드가 실행된다.
age = 27
if age == 27:
print(f"부럽네요...")
==# 부럽네요..
파이썬에서는 if 구문이 True일때 실행되어야 할 코드들이 indent 되어 있다.
if condition:
print("if statement code 1")
print("if statement code 2")
print("Not if statemet code")
if car == "현대":
print("현대는 국산차")
elif car == "기아":
print("기아는 국산차")
else:
print("외제차")
NOTE
and 와 or을 같이 사용할 수 있으며 이때 괄호를 적절히 사용하면 가독성을 높일 수 있다.```if (age > 19 and age < 30) or (married == True and income < 100000000): print("전세대출 우대자 이십니다")```