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 Merge Two Dictionaries
Python Dictionary update()
Python Program to Trim Whitespace From a String
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python Set symmetric_difference()
Python object()
Python Program to Parse a String to a Float or Int
Python List
Python String count()
Python Program to Remove Duplicate Element From a List
Python Operators
Python String find()
Python Exception Handling Using try, except and finally statement
Python String lower()
Python break and continue
Python Program to Display Fibonacci Sequence Using Recursion
Python Dictionary
Python complex()
Python Program to Find the Size (Resolution) of a Image
Python isinstance()
Python Set issubset()
Python Generators
Python Program to Illustrate Different Set Operations
Python Set issuperset()
Python String expandtabs()
Python String replace()
Python *args and **kwargs
Python Function Arguments
Python Program to Get the File Name From the File Path
Python Tuple count()
Python List copy()
Python Data Structures and Algorithms - Benjamin Baka