{"id":25492,"date":"2021-11-16T08:40:07","date_gmt":"2021-11-16T03:10:07","guid":{"rendered":"https:\/\/python-programs.com\/?p=25492"},"modified":"2021-11-16T08:40:07","modified_gmt":"2021-11-16T03:10:07","slug":"python-dict-function-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-dict-function-with-examples\/","title":{"rendered":"Python dict() Function with Examples"},"content":{"rendered":"

dict() Function in Python:<\/strong><\/p>\n

The dict() function is used to create a dictionary.<\/p>\n

A dictionary is an unordered, changeable, and indexed collection.<\/p>\n

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

dict(keyword arguments)<\/pre>\n

Parameters<\/strong><\/p>\n

keyword arguments:<\/strong> This is Required. You can use as many keyword arguments as you want, separated by a comma: key = value, key = value…<\/p>\n

Return Value:<\/strong><\/p>\n

dict() does not return any results (returns None).<\/p>\n

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

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

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

Given key-value pairs = (emp_name=\"sunny\", emp_id=2122, jobrole=\"software developer\")<\/pre>\n

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

The result dictionary is :\r\n{'emp_name': 'sunny', 'emp_id': 2122, 'jobrole': 'software developer'}<\/pre>\n

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

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

Given key-value pairs = (one=\"hello\", two=\"good\", three=\"morning\")<\/pre>\n

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

The result dictionary is :\r\n{'one': 'hello', 'two': 'good', 'three': 'morning'}<\/pre>\n

dict() Function with Examples in Python<\/h2>\n