Latest web development tutorials

Python dictionary (Dictionary) clear () method

description

Python dictionary (Dictionary) clear () function deletes all the elements in the dictionary.

grammar

clear () method syntax:

dict.clear()

parameter

  • NA.

return value

This function has no return value.

Examples

The following example shows the clear () function to use:

#!/usr/bin/python

dict = {'Name': 'Zara', 'Age': 7};

print "Start Len : %d" %  len(dict)
dict.clear()
print "End Len : %d" %  len(dict)

The above example output is:

Start Len : 2
End Len : 0