Python3 Dictionary clear() Method
Description
The Python dictionary clear() function deletes all elements in 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/python3
tinydict
=
{
'Name'
:
'Zara'
,
'Age'
:
7
}
(
"Dictionary length: %d"
%
len
(
tinydict
)
)
tinydict.
clear
(
)
(
"Dictionary length after deletion: %d"
%
len
(
tinydict
)
)
The output of the above example is:
字典长度 : 2
字典删除后长度 : 0
Python3 Dictionary