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 ord()
Python Program to Delete an Element From a Dictionary
Python map()
Python bytes()
Python Data Types
Python enumerate()
Python bin()
Python String lstrip()
Python Program to Check the File Size
Python List remove()
Python Custom Exceptions
Python Function Arguments
Python Program to Find Sum of Natural Numbers Using Recursion
Python Program to Add Two Numbers
Python Get Current time
Deep Learning in Python - LazyProgrammer
Python datetime
Python issubclass()
Python Generators
Python Program to Make a Simple Calculator
Python strftime()
Python Program to Display Fibonacci Sequence Using Recursion
Python Set issubset()
Python Closures
Python vars()
Python Set intersection_update()
Python Iterators
Python Program to Check Leap Year
Intelligent Projects Using Python - Santanu Pattanayak
Python String encode()
Python Tuple index()
Python frozenset()