Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Unit 1 — Logical Operators

Lesson 13 of 50 in the free Python Programming notes on Siksha Sarovar, written by Rohit Jangra.

Logical Operators

Logical operators combine boolean expressions.

OperatorMeaningExampleResult
andTrue if both operands are TrueTrue and FalseFalse
orTrue if at least one operand is TrueTrue or FalseTrue
notInverts the boolean valuenot TrueFalse
age = 20
has_id = True
print(age >= 18 and has_id)     # True
print(age < 18 or has_id)       # True
print(not has_id)               # False

Truth Table

ABA and BA or B
TrueTrueTrueTrue
TrueFalseFalseTrue
FalseTrueFalseTrue
FalseFalseFalseFalse

Short-Circuit Evaluation

Python stops evaluating as soon as the result is determined — and returns the actual operand value, not just True/False.

def check():
    print("check() called")
    return True

print(False and check())   # False -- check() never runs
print(True or check())     # True  -- check() never runs

# and/or return an operand, not necessarily a bool
print(0 or "default")      # 'default' (0 is falsy, so the second operand is returned)
print("hi" and "bye")      # 'bye' (both truthy, returns the last one)

Truthy and Falsy Values

Falsy: 0, 0.0, "", [], (), {}, None, False. Everything else is truthy.

if []:
    print("won't print")
if [1]:
    print("prints — non-empty list is truthy")