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 — Relational (Comparison) Operators

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

Relational Operators

Relational operators compare two values and always return a boolean (True/False).

OperatorMeaningExampleResult
==Equal to5 == 5True
!=Not equal to5 != 3True
>Greater than5 > 3True
<Less than5 < 3False
>=Greater than or equal to5 >= 5True
<=Less than or equal to5 <= 3False
a, b = 10, 20
print(a == b)   # False
print(a != b)   # True
print(a < b)    # True
print(a >= b)   # False

Chained Comparisons

Python allows chaining comparisons in a single readable expression — an equivalent and is implied.

x = 15
print(10 < x < 20)        # True  -> equivalent to (10 < x) and (x < 20)
print(1 <= x <= 10)       # False

Comparing Strings

Strings are compared lexicographically (character by character, based on Unicode code points).

print("apple" < "banana")   # True ('a' < 'b')
print("Apple" == "apple")   # False (case sensitive)

Comparing Different Types

Comparing incompatible types with </> raises TypeError in Python 3:

# print(5 < "5")   # TypeError: '<' not supported between 'int' and 'str'
print(5 == "5")     # False — == is allowed, just returns False