[요약] 파이썬(Python) 흐름제어 - 조건문
# 파이썬 흐름제어(제어문) # 조건문 코드 예제 print(type(True)) #print(type(False)) # # if문의 전형적인 형태 if True: print("Yes") # Yes if False: print("No") # 조건문이 False이기 때문에 실행되지 않음 else: print("Yes2") # Yes2 # 관계연산자 # 연산자 종류 : >,>=,<,<=,==,!= a = 10 b = 20 print(a==b) # False print(a != b) # True print(a >b) # False print(a >= b) # False print(a < b) # True print(a <= b) # True # 참(True) / 거짓(False)에 대한 판단종류 # 참 : "내용", [내용], (내용), {내용}, 1 # 거짓 : "", [], (), {}, 0 city = "" if city: print('>>>> True') else: print('>>>> False') # >>>> False # 논리연산자 # and or not a = 100 b = 60 c = 15 print('and : ', a>b and b b or c>b) # True print('not : ', not a>b) # True print(not False) # False print(not True) # True # 산술, 관계, 논리 연산자의 우선순위 # 산술 > 관계 > 논리 순으로 적용 print('예1 : ', 5 +10 > 0 and not 7 + 3 == 10) # False score1 = 90 score2 = 'A' if score1 >= 90 and score2 == 'A' : print("합격") # 합격 else: print("불합격") # 다중조건문 처리 num = 90 if num >= 90: print("num 등급 A", num) # num 등급 A 90 elif num >= 80: print("num 등급 B", num) elif num >= 70: print("num 등급 C", num) # 중첩조건문 처리 age = 27 height = 175 if age >= 20: if age >= 170: print("A지망 지원 가능") elif age >= 160: print("B지망 지원 가능") else: print("지원불가") # 지원불가 else: print("20세 이상 지원 가능")
'프로그래밍 > Python' 카테고리의 다른 글
[요약] 파이썬(Python) - 실용코드 - 반복/제어문 (0) | 2020.11.05 |
---|---|
[요약] 파이썬(Python) 흐름제어 - 반복문 (0) | 2020.10.23 |
[요약]파이썬(Python) 자료구조 TEST Sample (0) | 2020.09.15 |
[요약]파이썬(Python) 자료구조(List, Tuple) (0) | 2020.09.06 |
[요약]파이썬(Python) 문자형 처리 (0) | 2020.09.01 |