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 Exception Handling Using try, except and finally statement
Python String split()
Python repr()
Python timestamp to datetime and vice-versa
Python String encode()
Python Set discard()
Python String lstrip()
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python Program to Print Colored Text to the Terminal
Python Program to Display Fibonacci Sequence Using Recursion
Python Program to Find Factorial of Number Using Recursion
Python property()
Python Program to Get the Last Element of the List
Python Program to Find Armstrong Number in an Interval
Python Program to Check if a Number is Odd or Even
Python Program to Count the Occurrence of an Item in a List
Python Program to Print Output Without a Newline
Python @property decorator
Python Set difference()
Python Program to Differentiate Between type() and isinstance()
Python List sort()
Python Input, Output and Import
Python Program to Add Two Matrices
Python Program to Find Numbers Divisible by Another Number
Python Get Current time
Python Namespace and Scope
Python Program to Get Line Count of a File
Python Program to Get a Substring of a String
Python String zfill()
Python Set issubset()
Python String isnumeric()
Python Inheritance