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 Convert String to Datetime
Python Program to Differentiate Between del, remove, and pop on a List
Python Program to Check if a Number is Positive, Negative or 0
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python Object Oriented Programming
Python Set add()
Python Operator Overloading
Python Program to Get the Last Element of the List
Python String lstrip()
Python Program to Generate a Random Number
Python Program to Check If Two Strings are Anagram
Python Data Structures and Algorithms - Benjamin Baka
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python Program to Check Leap Year
Python Dictionary popitem()
Python Generators
Python String rsplit()
Python delattr()
Python Set issuperset()
Python Program to Capitalize the First Character of a String
Python Dictionary update()
Python *args and **kwargs
Python List sort()
Python Program to Count the Number of Occurrence of a Character in String
Python List remove()
Python bytearray()
Deep Learning with Python - Francois Cholletf
Python Closures
Python Tuple index()
Python Set difference()
Python Program to Check Armstrong Number
Python Program to Create a Long Multiline String