Back to course

Understanding Logical Operators (AND, OR, NOT)

Python Programming: The 0 to Hero Bootcamp

Logical Operators

Logical operators combine multiple Boolean expressions to produce a single Boolean result. They are essential for complex decision-making.

1. and

Returns True only if both operands are True.

ABA and B
TrueTrueTrue
TrueFalseFalse
FalseTrueFalse
FalseFalseFalse

python age = 25 country = 'USA'

result_and = (age >= 18) and (country == 'USA') print(result_and) # True

2. or

Returns True if at least one operand is True.

ABA or B
TrueTrueTrue
TrueFalseTrue
FalseTrueTrue
FalseFalseFalse

python day = 'Sunday'

is_weekend = (day == 'Saturday') or (day == 'Sunday') print(is_weekend) # True

3. not

Negates the Boolean value (inverts the result).

Anot A
TrueFalse
FalseTrue

python is_raining = False print(not is_raining) # True