🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Python Notes
Topic #74

Logical Operators


Python Logical Operators

Logical operators are used to combine conditional statements. Python has three logical operators:

  • and - Returns True if both statements are true
  • or - Returns True if one of the statements is true
  • not - Reverses the result, returns False if the result is true

The and Operator

The and keyword is a logical operator, and is used to combine conditional statements. Both conditions must be true for the entire expression to be true.

Example

a = 200
b = 33
c = 500
if a > b and c > a:
  print("Both conditions are True")

The or Operator

The or keyword is a logical operator, and is used to combine conditional statements. At least one condition must be true for the entire expression to be true.

Example

a = 200
b = 33
c = 500
if a > b or a > c:
  print("At least one of the conditions is True")

The not Operator

The not keyword is a logical operator, and is used to reverse the result of the conditional statement.

Example

a = 33
b = 200
if not a > b:
  print("a is NOT greater than b")

Combining Multiple Operators

You can combine multiple logical operators in a single expression. Python evaluates not first, then and, then or.

Example

age = 25
is_student = False
has_discount_code = True

if (age < 18 or age > 65) and not is_student or has_discount_code:
  print("Discount applies!")

Truth Tables

Understanding how logical operators work with different values:

and Operator Truth Table

Condition 1 Condition 2 Result
True True True
True False False
False True False
False False False

or Operator Truth Table

Condition 1 Condition 2 Result
True True True
True False True
False True True
False False False

Using Parentheses for Clarity

When combining multiple logical operators, use parentheses to make your intentions clear and control the order of evaluation.

Example

temperature = 25
is_raining = False
is_weekend = True

if (temperature > 20 and not is_raining) or is_weekend:
  print("Great day for outdoor activities!")

More Examples

Example

username = "Tobias"
password = "secret123"
is_verified = True

if username and password and is_verified:
  print("Login successful")
else:
  print("Login failed")

Example

score = 85

if score >= 0 and score <= 100:
  print("Valid score")
else:
  print("Invalid score")

Want to go beyond the notes?

Join CodingNow 2.0's Python course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Logical Operators – FAQs

Quick answers about learning Logical Operators in Python.

This free note from CodingNow 2.0 explains Logical Operators in Python — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Python topic on CodingNow 2.0, including Logical Operators, is 100% free with no signup required.
With focused practice, most students grasp Logical Operators in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now