{"id":23850,"date":"2021-10-05T20:28:49","date_gmt":"2021-10-05T14:58:49","guid":{"rendered":"https:\/\/python-programs.com\/?p=23850"},"modified":"2021-11-22T18:33:25","modified_gmt":"2021-11-22T13:03:25","slug":"python-program-for-dictionary-clear-function","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-dictionary-clear-function\/","title":{"rendered":"Python Program for Dictionary clear() Function"},"content":{"rendered":"

Dictionary in python :<\/strong><\/p>\n

A dictionary is a set of elements that have key-value pairs. The values in the elements are accessed using the element\u2019s keys.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given dictionary = {'hello': 100, 'this': 200, 'is': 300, 'btechgeeks': 400}<\/pre>\n

Output:<\/strong><\/p>\n

The given dictionary before clearing is :\r\n{'hello': 100, 'this': 200, 'is': 300, 'btechgeeks': 400}\r\nThe length of the given dictionary before clearing =  4\r\nThe given dictionary After clearing is :\r\n{}\r\nThe length of the given dictionary After clearing =  0<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given dictionary = {'good': '1', 'morning': '2', 'this': '3', 'is': '4', 'btechgeeks': '5'}<\/pre>\n

Output:<\/strong><\/p>\n

The given dictionary before clearing is :\r\n{'good': '1', 'morning': '2', 'this': '3', 'is': '4', 'btechgeeks': '5'}\r\nThe length of the given dictionary before clearing = 5\r\nThe given dictionary After clearing is :\r\n{}\r\nThe length of the given dictionary After clearing = 0<\/pre>\n

Program for Dictionary clear() Function in Python<\/h2>\n