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 Represent enum
Python globals()
Python List copy()
Python Program to Get the File Name From the File Path
Python String isalpha()
Python time Module
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python delattr()
Python String strip()
Python property()
Python List count()
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python Program to Swap Two Variables
Python Program to Illustrate Different Set Operations
Python Program to Iterate Over Dictionaries Using for Loop
Python Program to Convert Two Lists Into a Dictionary
Python Set difference_update()
Python Program to Get Line Count of a File
Python Objects and Classes
Python Program to Add Two Matrices
Python Program to Count the Number of Occurrence of a Character in String
Python RegEx
Python Multiple Inheritance
Python Program to Print Output Without a Newline
Python Program to Solve Quadratic Equation
Python input()
Python vars()
Python List pop()
Python Program to Return Multiple Values From a Function
Python list()
Python Dictionary items()
Python Program to Copy a File