Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Dictionary clear() method

Python Dictionary clear() method

Python Dictionary Python Dictionary


Description

The Python Dictionary clear() function removes all elements from a dictionary.

Syntax

clear() method syntax:



dict.clear()

Parameters

Return Value

This function has no return value.

Example

The following example shows how to use the clear() function:

Example

#!/usr/bin/python

tinydict

=

{

'Name'

:

'Zara'

,

'Age'

:

7

}

;

print

"Start Len : %d"

%  

len

(

tinydict

)

tinydict.

clear

(

)

print

"End Len : %d"

%  

len

(

tinydict

)

The output of the above example is:



Start Len : 2

End Len : 0

Python Dictionary Python Dictionary