Skip to content
Foxipa
Code Completion 4 Challenges

Complete the Python del statements code

Practice deleting name bindings, list targets, slices, and attributes with Python's del statement.

Intermediate ~8 min read

Challenge 1

Delete the temporary binding before the name is used again.

python Your answer
temporary = "remove me"
print(temporary)


try:
    print(temporary)
except NameError as error:
    print(type(error).__name__)

Press Ctrl⌘Enter to check your answer

Challenge 2

Remove the second item from the list.

python Your answer
colors = ["red", "green", "blue"]

print(colors)

Press Ctrl⌘Enter to check your answer

Challenge 3

Remove the middle two numbers from the list with a slice deletion.

python Your answer
numbers = [1, 2, 3, 4, 5]

print(numbers)

Press Ctrl⌘Enter to check your answer

Challenge 4

Delete the temporary attribute from the object.

python Your answer
class User:
    pass

user = User()
user.temp = 42

print(hasattr(user, "temp"))

Press Ctrl⌘Enter to check your answer