Python Dictionary clear()

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 = {}