Course Content
Python Data Structures
Python Data Structures
Clear() Method
Dictionaries also offer a handy clear()
method that removes all items, leaving you with an empty dictionary. Here's how it works.
numbers = {1: 1, 2: 4, 3: 9, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100} numbers.clear() print(numbers)
Let's put it to the test.
Task
Consider the dictionary below:
Your task is to clear out all the items in this dictionary.
Thanks for your feedback!
Clear() Method
Dictionaries also offer a handy clear()
method that removes all items, leaving you with an empty dictionary. Here's how it works.
numbers = {1: 1, 2: 4, 3: 9, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100} numbers.clear() print(numbers)
Let's put it to the test.
Task
Consider the dictionary below:
Your task is to clear out all the items in this dictionary.
Thanks for your feedback!
Clear() Method
Dictionaries also offer a handy clear()
method that removes all items, leaving you with an empty dictionary. Here's how it works.
numbers = {1: 1, 2: 4, 3: 9, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100} numbers.clear() print(numbers)
Let's put it to the test.
Task
Consider the dictionary below:
Your task is to clear out all the items in this dictionary.
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.
numbers = {1: 1, 2: 4, 3: 9, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100} numbers.clear() print(numbers)
Let's put it to the test.
Task
Consider the dictionary below:
Your task is to clear out all the items in this dictionary.