{"id":24064,"date":"2021-10-14T09:12:37","date_gmt":"2021-10-14T03:42:37","guid":{"rendered":"https:\/\/python-programs.com\/?p=24064"},"modified":"2021-11-05T17:13:36","modified_gmt":"2021-11-05T11:43:36","slug":"python-program-for-dictionary-setdefault-method","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-dictionary-setdefault-method\/","title":{"rendered":"Python Program for Dictionary setdefault() Method"},"content":{"rendered":"

In the previous article, we have discussed Python Program for floor() Function<\/a>
\nDictionary 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': 25, 'this': 35, 'is': 45, 'btechgeeks': 55}<\/pre>\n

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

The above given dictionary is :\r\n{'hello': 25, 'this': 35, 'is': 45, 'btechgeeks': 55}\r\nThe value at the given key hello =  25\r\nThe value at the given key btechgeeks=  55\r\nThe value at the given key good =  None\r\nThe value at the given key morning =  None<\/pre>\n

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

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

Given dictionary = {100: 'good', 150: 'morning', 200: 'btechgeeks'}<\/pre>\n

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

The above given dictionary is :\r\n{100: 'good', 150: 'morning', 200: 'btechgeeks'}\r\nThe value at the given key 200 =  btechgeeks\r\nThe value at the given key 10 =  None\r\nThe value at the given key 150 =  morning<\/pre>\n

Program for Dictionary setdefault() Method in Python<\/h2>\n