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 — Membership & Identity Operators

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

Membership and Identity Operators

Membership Operators — in, not in

Test whether a value exists within a sequence (string, list, tuple, dict, set).

OperatorMeaning
inReturns True if the value is found in the sequence
not inReturns True if the value is not found
fruits = ["apple", "banana", "mango"]
print("banana" in fruits)        # True
print("grape" not in fruits)     # True

text = "Python Programming"
print("Prog" in text)            # True
print("prog" in text)            # False (case sensitive)

marks = {"Amit": 85, "Riya": 92}
print("Amit" in marks)           # True -- checks keys, not values
print(85 in marks.values())      # True -- explicit values() check

---

Identity Operators — is, is not

Test whether two variables refer to the same object in memory (not just equal values).

OperatorMeaning
isTrue if both refer to the same object
is notTrue if they refer to different objects
a = [1, 2, 3]
b = [1, 2, 3]
c = a

print(a == b)     # True  -- same contents
print(a is b)     # False -- different objects in memory
print(a is c)     # True  -- c points to the same object as a
print(a is not b) # True

== vs is — the key distinction

  • == checks value equality (do they contain the same data?)
  • is checks identity (are they literally the same object?)
x = None
if x is None:      # correct, idiomatic way to check for None
    print("x has no value")
Always use is / is not when comparing against None, never ==.