Python Dictionary clear()

Python Dictionary clear()

The clear() method removes all items from the dictionary.

The syntax of clear() is:

dict.clear()

clear() Parameters

clear() method doesn't take any parameters.


Return Value from clear()

clear() method doesn't return any value (returns None).


Example 1: How clear() method works for dictionaries?

d = {1: "one", 2: "two"}

d.clear()
print('d =', d)

Output

d = {}