logo

Python Dictionary Clear() Method


Show

Description

Python dictionary method clear() eliminates entire articles from the dictionary. Clear() clears the similar dictionary that d and d2 together point at. d = {} will generate a new example for d excluding entire additional references will immobile point to the aged contents. ... clear() will rearrange the contents, however, all orientations to the identical example will still be right.

Syntax

Following is the syntax for the clear() method:

dict.clear()

Parameters

  • NA

Return Value

This method does not return any value.

Example

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

#!/usr/bin/python

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

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

Start Len : 2
End Len : 0

Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.