Menu
Coddy logo textTech

Logical Operators Part 2

Part of the Fundamentals section of Coddy's Python journey — lesson 16 of 77.

Logical operators have a special table called "Truth table" that shows what the combination of logical operators returns.

Truth table for the and operator:

aba and b
FalseFalseFalse
FalseTrueFalse
TrueFalseFalse
TrueTrueTrue

The only way to get a True for the and operator is if both a and b are True

Truth table for the or operator:

aba or b
FalseFalseFalse
FalseTrueTrue
TrueFalseTrue
TrueTrueTrue

In this case, to get a True result, either a or b should be True.

Truth table for the not operator:

anot a
FalseTrue
TrueFalse

Here the value of a is reversed. If a is False then not a is True

challenge icon

Challenge

Beginner

Replace the values of variables b1 and b2 with numbers so that b3 evaluates to True.

b3 will be True when the multiplication of b1 and b2 is greater than their addition.

Cheat sheet

Truth tables for logical operators in Python:

AND Operator

aba and b
FalseFalseFalse
FalseTrueFalse
TrueFalseFalse
TrueTrueTrue

OR Operator

aba or b
FalseFalseFalse
FalseTrueTrue
TrueFalseTrue
TrueTrueTrue

NOT Operator

anot a
FalseTrue
TrueFalse

Try it yourself

# Replace the values with numbers
b1 = ?
b2 = ?

# This line checks if b1 * b2 is greater than b1 + b2
b3 = (b1 * b2) > (b1 + b2)

# Don't change the line below
print(f"b3 = {b3}")
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals