Python Dictionary clear() method
Description
The Python Dictionary clear() function removes all elements from a dictionary.
Syntax
clear() method syntax:
dict.clear()
Parameters
- NA.
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
}
;
"Start Len : %d"
%
len
(
tinydict
)
tinydict.
clear
(
)
"End Len : %d"
%
len
(
tinydict
)
The output of the above example is:
Start Len : 2
End Len : 0
Python Dictionary