Course Content
Python Data Structures
Python Data Structures
The clear() Method
Just like in other data structures, the clear()
method completely wipes out all the elements.
Let's say you have a set of favorite movies, but you decide to start fresh and clear the collection:
# Define a set of favorite movies movies = {"Inception", "Interstellar", "Tenet"} print("Original set:", movies) # Clear the set movies.clear() print("After clearing:", movies)
Task
Swipe to start coding
You are given the set of the worst movies by audience ratings, worst_movies
.
Your goal:
- Clear this set.
- Use the
clear()
method to accomplish this.
Solution
Everything was clear?
Thanks for your feedback!
Section 4. Chapter 6
The clear() Method
Just like in other data structures, the clear()
method completely wipes out all the elements.
Let's say you have a set of favorite movies, but you decide to start fresh and clear the collection:
# Define a set of favorite movies movies = {"Inception", "Interstellar", "Tenet"} print("Original set:", movies) # Clear the set movies.clear() print("After clearing:", movies)
Task
Swipe to start coding
You are given the set of the worst movies by audience ratings, worst_movies
.
Your goal:
- Clear this set.
- Use the
clear()
method to accomplish this.
Solution
Everything was clear?
Thanks for your feedback!
Section 4. Chapter 6