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

Course Content

Python Data Structures

Python Data Structures

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

Clear() Method

Just like in other data structures, the clear() method completely wipes out all the elements. Let's dive into the example below.

12345
set_1 = {10, 'Joe', 'cat', True, 134} print(set_1) set_1.clear() print(set_1)
copy

Task

You've got the set:

Your task is to erase all the items from this set.

Task

You've got the set:

Your task is to erase all the items from this set.

Switch to desktop for real-world practiceContinue from where you are using one of the options below

Everything was clear?

Section 4. Chapter 6
toggle bottom row

Clear() Method

Just like in other data structures, the clear() method completely wipes out all the elements. Let's dive into the example below.

12345
set_1 = {10, 'Joe', 'cat', True, 134} print(set_1) set_1.clear() print(set_1)
copy

Task

You've got the set:

Your task is to erase all the items from this set.

Task

You've got the set:

Your task is to erase all the items from this set.

Switch to desktop for real-world practiceContinue from where you are using one of the options below

Everything was clear?

Section 4. Chapter 6
toggle bottom row

Clear() Method

Just like in other data structures, the clear() method completely wipes out all the elements. Let's dive into the example below.

12345
set_1 = {10, 'Joe', 'cat', True, 134} print(set_1) set_1.clear() print(set_1)
copy

Task

You've got the set:

Your task is to erase all the items from this set.

Task

You've got the set:

Your task is to erase all the items from this set.

Switch to desktop for real-world practiceContinue from where you are using one of the options below

Everything was clear?

Just like in other data structures, the clear() method completely wipes out all the elements. Let's dive into the example below.

12345
set_1 = {10, 'Joe', 'cat', True, 134} print(set_1) set_1.clear() print(set_1)
copy

Task

You've got the set:

Your task is to erase all the items from this set.

Switch to desktop for real-world practiceContinue from where you are using one of the options below
Section 4. Chapter 6
Switch 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