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 Remove Duplicate Element From a List
Python Anonymous / Lambda Function
Python Statement, Indentation and Comments
Python Dictionary fromkeys()
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python Variables, Constants and Literals
Python Program to Count the Number of Each Vowel
APIs in Node.js vs Python - A Comparison
Python exec()
Python Program to Remove Punctuations From a String
Python Program to Create a Long Multiline String
Python Program to Count the Number of Digits Present In a Number
Python del Statement
Deep Learning with Python - Francois Cholletf
Python open()
Python timestamp to datetime and vice-versa
Python List index()
Python abs()
Python tuple()
Python Strings
Python Program to Calculate the Area of a Triangle
Python Program to Access Index of a List Using for Loop
Python String join()
Python Data Types
Python String endswith()
Python String islower()
Python Program to Print the Fibonacci sequence
Python super()
Python Program to Count the Occurrence of an Item in a List
Python Modules
Python Dictionary update()
Python Program to Add Two Matrices