프로그래밍/Python

[Python] 조건문

eunki 2021. 5. 21. 00:29
728x90

if 조건문

if 조건식: 
    (Tab → indent 들여쓰기) 수행 코드


if True : if문에 종속되어있는 코드를 실행
if False : if문에 종속되어있는 코드를 실행 X

if 조건식:
    print('if문의 조건식이 참이면 수행')

 

 

if ~ else

if 조건식:
    print('if문의 조건식이 참이면 수행')
else:
    print('if문의 조건식이 거짓이면 수행')

print('if문과 별개적으로 수행')

 

 

if ~ elif ~ else

if 조건식:
    print('if문의 조건식이 참이면 수행')
elif 조건식:
    print('elif문의 조건식이 참이면 수행')
else:
    print('if문과 elif문의 조건식이 거짓이면 수행')

 

 

중첩 if문

if 조건식1:
    if 조건식2:
        print('if문의 조건식1과 조건식2가 참이면 수행')
    print('if문의 조건식1이 참이면 수행')
728x90