라일락 꽃이 피는 날

[Python] 조건문 본문

프로그래밍/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

'프로그래밍 > Python' 카테고리의 다른 글

[Python] tuple (튜플)  (0) 2021.05.30
[Python] 반복문  (0) 2021.05.21
[Python] random  (0) 2021.05.21
[Python] 연산자  (0) 2021.04.23
[Python] 입력 함수 input()  (0) 2021.04.23