# Boolean

  • Can be only True or False
bool1 = True
bool2 = False
1
2

# Logical operators

Symbol Meaning
== equal
!= not equal
< less than
> greater than
<= less than or equal
>= greater than or equal

# Gate

# And Gate

True  and True   == True
True  and False  == False
False and True   == False
False and False  == False
1
2
3
4

# Or Gate

True  or True   == True
True  or False  == True
False or True   == True
False or False  == False
1
2
3
4

# Not Gate

not True  == False
not False == True
1
2

# True or False ?

1 < 3
5 < 2
3 == 3
1
2
3
Solution

1 < 3
5 < 2
3 == 3

3 != 3
4 > 10
1 <= 3
1
2
3
Solution

3 != 3
4 > 10
1 <= 3

5 <= 5
99 != 99
4 >= 4
1
2
3
Solution

5 <= 5
99 != 99
4 >= 4

"Hello" == "hello"
3 == "3"
"Hi" == "Hi"
"Hehe" != "Hehe"
1
2
3
4
Solution

"Hello" == "hello"
3 == "3"
"Hi" == "Hi"
"Hehe" != "Hehe"

# Let's practice together

a = 5 > 3
print(a)
1
2
output

OUTPUT

True

a = 5 > 3
print(a and a>10)
1
2
output

OUTPUT

False

a = 5 > 3
b = 200 - 5 < 100
print(a or b)
1
2
3
output

OUTPUT

True

a = 5 > 3
b = a < 100
print(a or b)
1
2
3
output

OUTPUT

True

a = 5 > 3
b = a > 100
print(a and b)
1
2
3
output

OUTPUT

False

a = 10 < 5
b = 20 > 5
print(a and b and not b)
1
2
3
output

OUTPUT

False

a = 10 
b = 20
bool1 = a > 5
bool2 = b > a
print( (bool1 or bool2) and not bool2)

1
2
3
4
5
6
output

OUTPUT

False

a = 10 
b = 20
bool1 = a > 5
bool2 = b > a
print(bool1 or bool2 and not bool2)
1
2
3
4
5
output

OUTPUT

True

why?

short-circuit operator (opens new window)

or : This is a short-circuit operator, so it only evaluates the second argument if the first one is false.

and: This is a short-circuit operator, so it only evaluates the second argument if the first one is true.

# Exercise Book 08.Boolean