Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
The clear() Method | Set
Python Data Structures
course content

Course Content

Python Data Structures

Python Data Structures

1. List
2. Dictionary
3. Tuple
4. Set

book
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:

1234567
# Define a set of favorite movies movies = {"Inception", "Interstellar", "Tenet"} print("Original set:", movies) # Clear the set movies.clear() print("After clearing:", movies)
copy
Task
test

Swipe to show code editor

You want to reset your movie collection. Use the clear() method to remove all items from your favorite_movies set. Print the set after clearing it.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 4. Chapter 6
toggle bottom row

book
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:

1234567
# Define a set of favorite movies movies = {"Inception", "Interstellar", "Tenet"} print("Original set:", movies) # Clear the set movies.clear() print("After clearing:", movies)
copy
Task
test

Swipe to show code editor

You want to reset your movie collection. Use the clear() method to remove all items from your favorite_movies set. Print the set after clearing it.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 4. Chapter 6
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt