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 sorted()
Python Program to Print Output Without a Newline
Python delattr()
Python Objects and Classes
Python String isdecimal()
Python Global Keyword
Python round()
Deep Learning in Python - LazyProgrammer
Python Functions
Python Program to Add Two Numbers
Python Program to Iterate Over Dictionaries Using for Loop
Python String ljust()
Python Program to Concatenate Two Lists
Python Program to Shuffle Deck of Cards
Python String splitlines()
Python id()
Python Program to Find HCF or GCD
Python enumerate()
Python Dictionary fromkeys()
Python all()
Python Program to Find the Factors of a Number
Python Set union()
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj
Python strptime()
Python Set symmetric_difference_update()
Python String split()
Python Set pop()
Python range()
Python Program to Get the File Name From the File Path
Python reversed()
Python Set symmetric_difference()
Python String find()