Introduction to the Lesson

Booleans are like binary, having 2 possible values, but in Boolean, True is 1 and False is 0. By using boolean operators, a boolean value can be produced.

Important Vocabulary

  • Boolean
  • Relational Operator
  • Logical Operator

Boolean Operators

Boolean operators produces booleans after it is used between two values

Relational Operators

Relational Operators can work between any two values of the same type known as operands, provided that the type supports such types of operators They consist of the operators ==, !=, >, <, >=, <=, each one working the same way that they work as one would expect, with == being the replacement for equal to, since = is reserved for value assignments.

They also work on other types, such as string or list, and values at each index is compared in order to determine which one is greater for example: "abg"<"acd" returns True, since the computer first goes to a and a, after they are the same, they go to b and c, and since c is "greater" than b, "acd" is greater than "abg"

print("True:",4 4)
print("True:",1 0)
print("False:",7 3)
print("True:",5 6)
print("False:",7 8)
print("True:",3 3)
print('')

# Same as above, but now for other values other than int
print('True:',"as""as")
print("False",TrueFalse)
print("False:",[2,3,1][2,3,1])
print("True:",'af''bc')
print("False:",'ce''cf')
print("True:",[1,'b'][1,'a'])
print('')

Logical Operators

These are operators that works on operand(s) to produce a single boolean result. Examples include and, or, not.

and returns true when both operands around it is true.

or returns true when at least one of its operands is true.

not returns true when the boolean after it is false.

They work the same way in binary, returning a specific value after specific inputs that is shown in a Truth Table

print("True:", True False)
print("False:",  True)
print("True:", True True)
print("False:",  True)
print("False:", True False)
print("True:",  False)

Combination of Relational and Logical Operators and the Procedure of Operations

Relational and Logical Operators can work by a set of precedece, a set of order that the computer understands the operations on.

Relational Operators goes first, and then Logical operators work in order of not, and, or

as usual, things in the parenthesis takes precedence over others

print( 3 3 4 6 5 7)