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 μ κ°λ€.