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 Count the Number of Digits Present In a Number
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python Program to Differentiate Between type() and isinstance()
Python Program to Slice Lists
Python zip()
Python Program to Iterate Over Dictionaries Using for Loop
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj
Python enumerate()
Python List
Python Program to Print Hello world!
Python tuple()
Python Program to Check if a Number is Odd or Even
Python Program to Print Output Without a Newline
Python Program to Trim Whitespace From a String
Python String index()
Python String translate()
Python pass statement
APIs in Node.js vs Python - A Comparison
Python Closures
Python String join()
Python any()
Python Dictionary setdefault()
Python Program to Get the Class Name of an Instance
Machine Learning with Python for everyone - Mark E.Fenner
Python Set issubset()
Python memoryview()
Python Program to Delete an Element From a Dictionary
Python Program to Split a List Into Evenly Sized Chunks
Python Program to Check if a Key is Already Present in a Dictionary
Python String expandtabs()
Python oct()
Python Set add()