bool
: 불리언 boolean<aside> 💡 참과 거짓 둘 중 하나의 값만 갖는 자료형입니다.
</aside>
bool1 = True
bool2 = False
# not 연산자 : 불리언의 값을 반전
bool3 = not bool1
bool4 = not bool2
bool5 = not (1 < 2)
bool6 = not(not (1 < 2))
pass
and
와 or
and
: 양쪽 모두 True
일 때만 True
반환or
: 양쪽 중 하나만 True
면 True
반환bl_1 = True and True
bl_2 = True and False
bl_3 = False and True
bl_4 = False and False
bl_5 = True or True
bl_6 = True or False
bl_7 = False or True
bl_8 = False or False
pass
x = 3
y = 4
# 비교 연산자 등의 반환값
bl_1 = x < y and x % 2 == 0
bl_2 = x < y and x % 2 == 1
bl_3 = x > y or x % 2 == 0
bl_4 = x < y or x % 2 == 0
pass
💡 연속 비교
bl_1 = 3 < 4
bl_2 = 3 < 4 <= 5 > 1
bl_3 = 3 < 4 <= 5 > 7
bl_4 = (1 + 5) == (2 * 3) == (1 * 6)
bl_5 = (1 + 5) == (2 * 3) == (1 * 7)
pass
대응하는 숫자값
# 모두 참 - 각각 1과 0에 대응
bl_1 = True == 1
bl_2 = False == 0
bl_3 = True == 1.0
bl_4 = False == 0.0
# 모두 거짓 - 다른 숫자들에는 대응하지 않음
bl_5 = True == 2
bl_6 = True == -1
bl_7 = False == 2
bl_8 = False == -1
pass