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 list()
Python Program to Find Hash of File
Python Program to Check if a Number is Positive, Negative or 0
Python frozenset()
Python String isidentifier()
Python String ljust()
Python Program to Capitalize the First Character of a String
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python Matrices and NumPy Arrays
Python Program to Add Two Numbers
Python String startswith()
Python Program to Generate a Random Number
Python Program Read a File Line by Line Into a List
Python Type Conversion and Type Casting
Python String isalnum()
Python help()
Python vars()
Python Functions
Python dict()
Python Generators
Python Set remove()
Python Program to Remove Duplicate Element From a List
Python Dictionary keys()
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python Program to Remove Punctuations From a String
Python all()
Python getattr()
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python Program to Get a Substring of a String
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python callable()
Python Program to Access Index of a List Using for Loop