Python dictionary clear() Method


Contents

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 clear() method:

dict.clear()

Parameters

  • NA

Return Value

This method does not return any value.

Example

The following example shows the usage of 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 above program, it produces 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.



Navigation
Tutorial
Tutorial
Tutorial