10 How to Use IN and IS operator in Python + Tips (Video in Khmer)
Learn Python in, not in, is and is not operators with list, string, tuple and None. Simple example and tips. Good for beginner!
2026-10-22 ยท 4 min read
Hello friend! ๐ Python have 2 special operator: in and is. They look easy, but many beginner mix them.
In this post, I show you IN and IS operator in Python. Easy and short. ๐
๐ IN Operator
in check if item exist inside something. Result is True or False. Use not in for opposite.
With List
fruits = ["apple", "banana", "orange"]
print("apple" in fruits) # True
print("mango" in fruits) # False
print("mango" not in fruits) # True
With String
Check if text exist inside text.
text = "I love Python"
print("love" in text) # True
print("Python" in text) # True
print("python" in text) # False (big and small letter different)
With Tuple
Tuple is like list, but cannot change. Use ( ).
colors = ("red", "green", "blue")
print("red" in colors) # True
print("pink" in colors) # False
With Dictionary
in check the key, not the value.
user = {"name": "Dara", "age": 20}
print("name" in user) # True
print("Dara" in user) # False
print("Dara" in user.values()) # True
Use with if
role = "admin"
if role in ("admin", "editor"):
print("Can edit")
else:
print("Read only")
๐ฅ Video: Using IN Operator (List, String, Tuple) in Python (Khmer)
๐ IS Operator
is check if two variable are the same object in memory. Use is not for opposite.
== check same value. is check same object. Not same thing!
a = [1, 2, 3]
b = [1, 2, 3]
c = a
print(a == b) # True same value
print(a is b) # False different object (2 box)
print(a is c) # True same object (1 box, 2 name)
Think like this: a and b are two paper with same words. a and c are same paper.
Proof with id()
print(id(a)) # 140234...
print(id(b)) # 140235... (different)
print(id(c)) # 140234... (same as a)
Same id = same object = is give True.
Best Use: Check None
None mean "no value". Always use is with None.
result = None
if result is None:
print("No data yet")
if result is not None:
print("Have data")
Same for True and False singleton check:
flag = True
print(flag is True) # True
๐ฅ Video: Using IS Operators in Python (Khmer)
๐ IN vs IS vs ==
| Operator | Question | Example |
|---|---|---|
in | Item exist inside? | "a" in "cat" โ True |
== | Same value? | [1] == [1] โ True |
is | Same object? | [1] is [1] โ False |
โ Common Error
Use is to compare value:
name = "Dara"
if name is "Dara": # SyntaxWarning, not reliable
print("Hi")
Fix: use ==
if name == "Dara":
print("Hi")
Use == None:
if result == None: # work, but not best
pass
Fix: if result is None:
Think in check value in dictionary:
user = {"name": "Dara"}
print("Dara" in user) # False
print("Dara" in user.values()) # True
Use in on number:
print(2 in 123) # TypeError: argument of type 'int' is not iterable
Fix: print("2" in str(123))
๐ก Tips
- Use
into check beforeremove()from list. No error! - Use
inwith tuple or set for manyor:if x in (1, 2, 3):is cleaner thanx == 1 or x == 2 or x == 3. inon string check part of text.inon list check whole item:"py" in "python"โTrue,"py" in ["python"]โFalse- Use
==for value. Useisfor None only (andTrue/False). - Don't use
iswith number or string. Result may surprise you. - Use
is not Noneโ better thannot x is None. - Use
id()if you want see if 2 variable are same object. - Big list?
inis slow. Use set for fast check.
โ Any Question?
Tell us in comment below! ๐
#Python #InOperator #IsOperator #None #LearnPython #Beginner