1. What does this == vs is code print?
a = [1, 2, 3]
b = [1, 2, 3]
c = a
print(a == b)
print(a is b)
print(a is c)
Output:
True
False
True
== compares values — a and b have equal contents, so True. is compares identity — a and b are two separately created lists, so False. c is a reference to the very same list as a, so a is c is True. This is the foundational comparison question in Python interviews.
2. What does this list-in-list comparison print?
x = [[1, 2], [3, 4]]
y = [[1, 2], [3, 4]]
print(x == y)
print(x is y)
Output:
True
False
== on lists is recursive: it compares element-by-element, and since both inner lists are also equal by value, x == y is True. The lists are distinct objects in memory, so is is False. == works this way for any deeply nested structure of equal-comparable elements.
3. What does this None comparison code print?
value = None
print(value is None)
print(value == None)
Output:
True
True
None is a singleton — there is exactly one None object. Both is and == give True. The Pythonic convention is to compare with is None (not == None) because is cannot be overloaded, so no custom __eq__ can lie about it. This is a style question that shows up constantly.
4. What does this string comparison code print?
print("apple" < "banana")
print("abc" < "abd")
print("10" < "9")
print("a" < "B")
Output:
True
True
True
False
Strings compare lexicographically by Unicode code point. "abc" < "abd" is True because c < d. "10" < "9" is True — the comparison is char-by-char: '1' has code point 49, less than '9' (57) — it does not parse the numbers. "a" < "B" is False because uppercase letters (65–90) come before lowercase (97–122) in Unicode.
5. What does this number comparison code print?
print(1 == 1.0)
print(1 < 1.5)
print(True == 1)
print(False == 0)
Output:
True
True
True
True
int and float compare by numeric value, so 1 == 1.0 is True. bool is a subclass of int with values True == 1 and False == 0. These cross-type equality surprises are a favorite interview probe.
6. What does this tuple comparison code print?
print((1, 2) == (1, 2))
print((1, 2) < (1, 3))
print((2, 0) < (1, 9))
Output:
True
True
False
Tuples compare element-by-element, left to right. (1, 2) < (1, 3) is True because the first elements are equal and 2 < 3. (2, 0) < (1, 9) is False because the first elements differ: 2 < 1 is already False — later elements are never considered. This is the same ordering used by sorted() and max() on tuples.
7. What does this mixed-type equality print?
print(1 == "1")
print([1, 2] == (1, 2))
print({1, 2} == {2, 1})
Output:
False
False
True
Different types are not equal even when their printed form looks similar: 1 != "1" and a list is never equal to a tuple with the same elements. But a set compares by membership, and sets are unordered — so {1, 2} == {2, 1} is True.
8. What does this float precision comparison print?
print(0.1 + 0.2 == 0.3)
print(abs((0.1 + 0.2) - 0.3) < 1e-9)
Output:
False
True
0.1 + 0.2 is 0.30000000000000004 in binary floating point, so exact equality with 0.3 is False. Comparing with a tolerance (abs(diff) < 1e-9) works. This is the most repeated float-comparison question in Python interviews.
9. What does this chained comparison print?
print(1 < 2 < 3)
print(5 > 10 == 5)
print(1 < 2 == 2 < 3)
Output:
True
False
True
Chained comparisons like a < b == c < d are evaluated as (a < b) and (b == c) and (c < d), with each middle operand evaluated once. So 5 > 10 == 5 is (5 > 10) and (10 == 5) = False and False = False, and 1 < 2 == 2 < 3 is True and True and True = True.
10. What does this is on empty containers print?
print([] is [])
print(() is ())
print({} is {})
print(None is None)
Output:
False
True
False
True
The empty tuple () is a compile-time constant, so every () literal is the same object — () is () is True. But [] and {} are mutable, so each literal creates a new object and is is False. And None is a singleton, so None is None is True.
11. What does this list-slice copy comparison print?
a = [1, 2, 3]
b = a[:]
b.append(4)
print(a == b)
print(a is b)
Output:
False
False
a[:] creates a shallow copy — a brand-new list object with the same elements. b.append(4) mutates only the copy, so a and b now hold different values (a == b is False) and they are different objects (a is b is False).
12. What does this sorted comparison print?
data = [("b", 2), ("a", 3), ("a", 1)]
print(sorted(data))
Output:
[('a', 1), ('a', 3), ('b', 2)]
sorted orders tuples by the first element first, then the second. ("a", 1) and ("a", 3) share the first element, so they are ordered by the second: 1 then 3. All "a" tuples come before ("b", 2) because "a" < "b".
13. What does this in-membership comparison print?
print(2 in [1, 2, 3])
print(4 in {1, 2, 3})
print("b" in {"a": 1, "b": 2})
print(2 in (1, 2, 3))
Output:
True
False
True
True
in checks membership: against a list or tuple it scans the elements, against a set it does a hash lookup, and against a dict it checks the keys (not values). So "b" in {"a": 1, "b": 2} is True because "b" is a key. This dict-vs-list in distinction is commonly tested.
14. What does this identity-after-computation print?
a = 1000
b = a + 0
print(a == b)
print(a is b)
Output:
True
False
a + 0 computes a new int object 1000 at runtime. Value equality holds (a == b is True), but identity does not — the result of a + 0 is a distinct object from the literal 1000, so a is b is False. (Only the -5..256 cache guarantees shared objects, and arithmetic results are not cached.)
15. What does this custom-class equality print?
class Student:
def __init__(self, name, roll):
self.name = name
self.roll = roll
s1 = Student("A", 1)
s2 = Student("A", 1)
print(s1 == s2)
print(s1 is s2)
Output:
False
False
By default, == on a class you define falls back to identity — the same as is. Two Student("A", 1) instances are separate objects with identical attributes, but Python does not auto-compare attributes. s1 == s2 is False unless you implement __eq__. This is the classic “why do two identical objects compare unequal?” question.
Premium Content
Unlock Comparison Questions - Part 1 and all premium lessons with a subscription.
From ₹199.99/year — See plans