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 Number is Positive, Negative or 0
Python Keywords and Identifiers
Python open()
Python Program to Check Whether a String is Palindrome or Not
Python Program to Append to a File
Python Program to Return Multiple Values From a Function
Python Custom Exceptions
Python Program to Represent enum
Python Shallow Copy and Deep Copy
Python Program to Get Line Count of a File
Python List
Python issubclass()
Python File I/O Operation
Python bool()
Python List remove()
Python range()
Python super()
Python isinstance()
Python Program to Delete an Element From a Dictionary
Python String isdecimal()
Python Program to Get the File Name From the File Path
Python Program to Print Hello world!
Python Program to Measure the Elapsed Time in Python
Python Input, Output and Import
Python Statement, Indentation and Comments
Python delattr()
Python Program to Print all Prime Numbers in an Interval
Python List copy()
Python int()
Python Program to Capitalize the First Character of a String
Python strptime()
Python Program to Count the Number of Digits Present In a Number