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

Python3 Dictionary clear() Method

Python3 Dictionary clear() Method

Python3 Dictionaries Python3 Dictionary


Description

The Python dictionary clear() function deletes all elements in 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/python3

tinydict

=

{

'Name'

:

'Zara'

,

'Age'

:

7

}

print

(

"Dictionary length: %d"

%  

len

(

tinydict

)

)

tinydict.

clear

(

)

print

(

"Dictionary length after deletion: %d"

%  

len

(

tinydict

)

)

The output of the above example is:


字典长度 : 2
字典删除后长度 : 0

Python3 Dictionaries Python3 Dictionary