Search
Duplicate

Control Flow

νƒœκ·Έ
쑰건문
Bool
λΆˆν˜• 을 λ‹€μŒκ³Ό 같이 ν‘œν˜„ν•  수 μžˆλ‹€.
λ³€μˆ˜μ— μ°Έκ³Ό 거짓을 λΆ€μ—¬ν•  λ•Œ, True 와 False λ₯Ό μ‚¬μš©ν•œλ‹€.
set_to_true = True set_to_false = False
Python
볡사
λ³€μˆ˜λ₯Ό λΆˆν˜• ν‘œν˜„κ³Ό 같이 μ“Έ 수 μžˆλ‹€.
bool_one = 5 != 7 bool_two = 1 + 1 != 2 bool_three = 3 * 3 == 9
Python
볡사
νƒ€μž…μ„ 확인 ν•  λ•ŒλŠ” type(λ³€μˆ˜λͺ…) 을 μ‚¬μš©ν•˜λ©΄ λœλ‹€.
Boolean Operators
boolean operator 의 μ’…λ₯˜λ‘œλŠ” 세가지가 μžˆλ‹€. and or not
μ—°μ‚°μž
μ—­ν• 
and
두 개의 뢈 ν‘œν˜„μ΄ κ°™μœΌλ©΄ True λ₯Ό, μ•„λ‹ˆλ©΄ False λ₯Ό λ°˜ν™˜ν•œλ‹€.
or
두 개의 뢈 ν‘œν˜„ 쀑 ν•˜λ‚˜λ§Œ 같아도 True λ₯Ό λ°˜ν™˜ν•œλ‹€.
not
뢈 ν‘œν˜„μ˜ 뢈 값을 μ •λ°˜λŒ€λ‘œ λ§Œλ“ λ‹€.
not 의 예제
not True == False not False == True
Python
볡사
If
if 문을 μ“°κ³  μ‹Άλ‹€λ©΄ μ•„λž˜μ™€ 같은 ꡬ문을 μ‚¬μš©ν•˜λ©΄ λœλ‹€.
if [쑰건] :
if is_raining: print("bring an umbrella") if 2 == 4 - 2: print("apple")
Python
볡사
elif 와 else λŠ” if λ¬Έ μ•„λž˜ μ“°λ©΄λ˜κ³  ꡬ문은 κ°™λ‹€.
elif λŠ” μžλ°”μ—μ„œ else if 와 κ°™λ‹€.