Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does the is operator check in Python?
The is operator checks if two variables point to the exact same object in memory.
Click to reveal answer
beginner
What is the difference between == and is?
== checks if values are equal, while is checks if two variables are the same object in memory.
Click to reveal answer
beginner
What does the is not operator do?
is not checks if two variables do NOT point to the same object in memory.
Click to reveal answer
beginner
Given a = [1, 2] and b = a, what will a is b return?
It will return True because both a and b point to the same list object.
Click to reveal answer
intermediate
Why might a == b be True but a is b be False?
Because a and b have the same value but are different objects in memory.
Click to reveal answer
What does is check in Python?
AIf two variables refer to the same object
BIf two variables have the same value
CIf two variables are of the same type
DIf two variables are both numbers
✗ Incorrect
is checks if two variables point to the same object in memory.
What will 5 is 5 return in Python?
AError
BFalse
CTrue
DDepends on Python version
✗ Incorrect
Small integers are cached in Python, so 5 is 5 returns True.
If a = [1, 2] and b = [1, 2], what does a is b return?
ATrue
BFalse
CDepends on list size
DError
✗ Incorrect
Lists with the same content are different objects, so a is b is False.
Which operator checks if two variables do NOT point to the same object?
A!=
B!==
Cnot equal
Dis not
✗ Incorrect
is not checks if two variables are not the same object.
What is the result of 'hello' is 'hello' in Python?
ADepends on Python implementation
BFalse
CError
DTrue
✗ Incorrect
Python often interns short strings, so identical string literals usually point to the same object, but this behavior can depend on the Python implementation.
Explain in your own words what the is operator does in Python.
Think about whether two variables are the exact same thing, not just equal.
You got /3 concepts.
Describe a situation where a == b is True but a is b is False.
Consider two separate lists with the same content.
You got /3 concepts.
Practice
(1/5)
1. What does the is operator check in Python?
easy
A. If two variables are of the same type
B. If two variables have the same value
C. If two variables point to the same object
D. If two variables are both numbers
Solution
Step 1: Understand the is operator
The is operator checks whether two variables refer to the exact same object in memory.
Step 2: Differentiate from equality
Unlike ==, which checks if values are equal, is checks identity, meaning the same object.
Final Answer:
If two variables point to the same object -> Option C
Quick Check:
is checks object identity = C [OK]
Hint: Remember: is means same object, not just equal value [OK]
Common Mistakes:
Confusing is with ==
Thinking is checks value equality
Assuming is works like type comparison
2. Which of the following is the correct syntax to check if variable a is not the same object as b?
easy
A. a != b
B. a is not b
C. a not is b
D. a !== b
Solution
Step 1: Identify the correct identity operator
The operator to check if two variables are not the same object is is not.
Step 2: Check syntax correctness
a is not b is the correct syntax; other options are either value comparison or invalid syntax.
Final Answer:
a is not b -> Option B
Quick Check:
Correct syntax for identity not equal = D [OK]
Hint: Use is not to check different objects, not != [OK]
Common Mistakes:
Using != instead of is not
Writing not is which is invalid
Using JavaScript style !== in Python
3. What will be the output of this code?
list1 = [1, 2, 3]
list2 = list1
list3 = [1, 2, 3]
print(list1 is list2)
print(list1 is list3)
medium
A. True\nFalse
B. True\nTrue
C. False\nTrue
D. False\nFalse
Solution
Step 1: Analyze list1 is list2
Since list2 = list1, both point to the same object, so this is True.
Step 2: Analyze list1 is list3
list3 is a new list with the same values but a different object, so this is False.
Final Answer:
True\nFalse -> Option A
Quick Check:
Same object check = True, different object = False [OK]
Hint: Same variable means is True; identical values but new object means False [OK]
Common Mistakes:
Assuming identical lists are the same object
Confusing is with ==
Ignoring that assignment copies reference, not value
4. Find the error in this code snippet:
a = None
if a is not None:
print("Value exists")
else
print("No value")
medium
A. Missing colon after else
B. Wrong use of is not
C. None should be in quotes
D. Indentation error
Solution
Step 1: Check syntax of if-else statement
The else line is missing a colon at the end, which is required in Python.
Step 2: Verify other parts
The use of is not with None is correct, and None is a keyword, so no quotes needed. Indentation looks fine.
Final Answer:
Missing colon after else -> Option A
Quick Check:
Colon needed after else = A [OK]
Hint: Always put a colon after else in Python [OK]
Common Mistakes:
Forgetting colon after else
Using quotes around None
Misusing is not operator
5. You want to check if a variable x is exactly None before processing it. Which is the best way to do this?
hard
A. if x is not None:
B. if x == None:
C. if x != None:
D. if x is None:
Solution
Step 1: Understand the difference between == and is for None
None is a singleton object in Python. The recommended way to check for it is using is because it checks identity.
Step 2: Choose the correct condition for checking if x is None
if x is None: correctly checks if x points to the None object.