Table of Contents
The clear() method removes all items from the dictionary.
The syntax of clear() is:
dict.clear()
1. clear() Parameters
clear() method doesn’t take any parameters.
2. Return Value from clear()
clear() method doesn’t return any value (returns None).
3. Example 1: How clear() method works for dictionaries?
d = {1: "one", 2: "two"}
d.clear()
print('d =', d)
Output
d = {}
Related posts:
Python Program to Check if a Key is Already Present in a Dictionary
Python Program to Compute the Power of a Number
Python File I/O Operation
Python Recursion
Python Program to Delete an Element From a Dictionary
Python Program to Check if a Number is Odd or Even
Python Program to Check If a List is Empty
Python Multiple Inheritance
Python Program to Create a Long Multiline String
Python callable()
Python Program to Check If Two Strings are Anagram
Python Program to Safely Create a Nested Directory
Python Program to Find All File with .txt Extension Present Inside a Directory
Python datetime
Python if...else Statement
Python Set difference()
Python Sets
Python classmethod()
Python String expandtabs()
Python Package
Python Program to Print Output Without a Newline
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Python String index()
Python hash()
Python Program to Check Whether a String is Palindrome or Not
Python Program to Randomly Select an Element From the List
Python RegEx
Python set()
Python Set discard()
Python Program to Differentiate Between type() and isinstance()
Python List remove()
Python frozenset()