0
0
Pythonprogramming~10 mins

Identity operators (is, is not) in Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if two variables refer to the same object using the identity operator.

Python
result = (a [1] b)
print(result)
Drag options to blanks, or click blank then click option'
Ais
B==
C!=
Dis not
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of 'is' to check identity.
Using '!=' or 'is not' when the question asks for identity check.
2fill in blank
medium

Complete the code to check if two variables do NOT refer to the same object using the identity operator.

Python
if x [1] y:
    print("Different objects")
else:
    print("Same object")
Drag options to blanks, or click blank then click option'
Ais
B==
C!=
Dis not
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' which checks value inequality, not identity.
Using 'is' instead of 'is not' for checking different objects.
3fill in blank
hard

Fix the error in the code to correctly check if two lists are the same object.

Python
list1 = [1, 2, 3]
list2 = list1
print(list1 [1] list2)
Drag options to blanks, or click blank then click option'
A==
B!=
Cis
Dis not
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' which checks value equality, not identity.
Using 'is not' or '!=' which check for inequality.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that includes only items where the key is not the same object as the value and the value is None.

Python
filtered = {k: v for k, v in data.items() if k [1] v and v [2] None}
Drag options to blanks, or click blank then click option'
Ais not
Bis
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of 'is not' for identity check.
Using '==' instead of 'is' to check for None.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase keys to values only if the key is the same object as the value and the value is not None.

Python
result = {k[1]: v for k, v in items if k [2] v and v [3] None}
Drag options to blanks, or click blank then click option'
A.upper()
Bis
Cis not
D.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.lower()' instead of '.upper()' for keys.
Using '==' or '!=' instead of 'is' or 'is not' for identity checks.