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 Parse a String to a Float or Int
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python locals()
Python Program to Shuffle Deck of Cards
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python Modules
Python Program to Find Sum of Natural Numbers Using Recursion
Python Program to Get the Class Name of an Instance
Python Program to Get a Substring of a String
Python Program to Count the Number of Occurrence of a Character in String
Python Program to Count the Occurrence of an Item in a List
Python Program to Compute the Power of a Number
Python Keywords and Identifiers
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python String center()
Python tuple()
Python str()
Python String partition()
Python Program to Return Multiple Values From a Function
Python format()
Python eval()
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python repr()
Python Program to Measure the Elapsed Time in Python
Python String isnumeric()
Python Set add()
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python min()
Python Sets
Python help()
Python String startswith()