Python 3 - dictionary clear() Method


Advertisements

Description

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

Syntax

Following is the syntax for clear() method −

dict.clear()

Parameters

NA

Return Value

This method does not return any value.

Example

The following example shows the usage of clear() method.

#!/usr/bin/python3

dict = {'Name': 'Zara', 'Age': 7}
print ("Start Len : %d" %  len(dict))

dict.clear()
print ("End Len : %d" %  len(dict))

Result

When we run above program, it produces the following result −

Start Len : 2
End Len : 0
python_dictionary.htm
Advertisements