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

Course Content

Python Data Structures

Python Data Structures

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

bookClear() Method

Dictionaries also offer a handy clear() method that removes all items, leaving you with an empty dictionary. Here's how it works.

123
numbers = {1: 1, 2: 4, 3: 9, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100} numbers.clear() print(numbers)
copy

Let's put it to the test.

Task

Consider the dictionary below:

Your task is to clear out all the items in this dictionary.

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 2. Chapter 8
toggle bottom row

bookClear() Method

Dictionaries also offer a handy clear() method that removes all items, leaving you with an empty dictionary. Here's how it works.

123
numbers = {1: 1, 2: 4, 3: 9, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100} numbers.clear() print(numbers)
copy

Let's put it to the test.

Task

Consider the dictionary below:

Your task is to clear out all the items in this dictionary.

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 2. Chapter 8
toggle bottom row

bookClear() Method

Dictionaries also offer a handy clear() method that removes all items, leaving you with an empty dictionary. Here's how it works.

123
numbers = {1: 1, 2: 4, 3: 9, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100} numbers.clear() print(numbers)
copy

Let's put it to the test.

Task

Consider the dictionary below:

Your task is to clear out all the items in this dictionary.

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!

Dictionaries also offer a handy clear() method that removes all items, leaving you with an empty dictionary. Here's how it works.

123
numbers = {1: 1, 2: 4, 3: 9, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100} numbers.clear() print(numbers)
copy

Let's put it to the test.

Task

Consider the dictionary below:

Your task is to clear out all the items in this dictionary.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 2. Chapter 8
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
some-alt