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 String isupper()
Python timestamp to datetime and vice-versa
Python Program to Check the File Size
Python String join()
Python String casefold()
Python getattr()
Python Set intersection_update()
Python String lstrip()
Python Program to Get File Creation and Modification Date
Python Dictionary fromkeys()
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python Machine Learning Eqution Reference - Sebastian Raschka
Python open()
Python Program to Delete an Element From a Dictionary
Python Program to Find Factorial of Number Using Recursion
Python Multiple Inheritance
Python Shallow Copy and Deep Copy
Python len()
Python Program to Find All File with .txt Extension Present Inside a Directory
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python String isalpha()
Python Program to Display the multiplication Table
Python Program to Catch Multiple Exceptions in One Line
Python Dictionary
Python Program to Check Whether a String is Palindrome or Not
Python for Loop
Python strftime()
Python range()
Python Variables, Constants and Literals
Python Program to Check if a Number is Odd or Even
Python Program to Safely Create a Nested Directory
Python Functions