Boolean Values
What are Booleans?
Booleans are a data type that can hold one of two values: True or False. They are used to represent truth values and are essential for making decisions in your programs.
is_true = True
is_false = False
Boolean Expressions
Boolean expressions are expressions that evaluate to either True or False. They are commonly used in conditional statements and loops. There are two kind of operators. Relational and Logical Operators.
a = 10
b = 5
# Greater than
print(a > b)
# Output: True
# Less than
print(a < b)
# Output: False
# Equal to
print(a == b)
# Output: False
# Not equal to
print(a != b)
# Output: True
# Greater than or equal to
print(a >= b)
# Output: True
# Less than or equal to
print(a <= b)
# Output: False
x = True
y = False
# AND operator
result = x and y
# Output: False --> because not both are true (would be true if x and y are true)
# OR operator
result = x or y
# Output: True --> gets true if one of both variables are true
# NOT operator
result = not x
# Output: False --> 'not' turns around true and false