Easy Tutorial
❮ Ref Set Clear Python Reversing List ❯

Python3 Dictionary clear() Method

Python3 Dictionary


Description

The Python dictionary clear() function is used to remove all elements from the dictionary.

Syntax

Syntax for the clear() method:

dict.clear()

Parameters

Return Value

This function does not return any value.

Example

The following example demonstrates the use of the clear() function:

#!/usr/bin/python3

tinydict = {'Name': 'Zara', 'Age': 7}

print("Dictionary length: %d" % len(tinydict))
tinydict.clear()
print("Dictionary length after clearing: %d" % len(tinydict))

Output of the above example:

Dictionary length: 2
Dictionary length after clearing: 0

Python3 Dictionary

❮ Ref Set Clear Python Reversing List ❯