Home »
Python
dict() function with example in Python
Python dict() function: Here, we are going to learn about the dict() function in Python with example.
Submitted by IncludeHelp, on April 04, 2019
Python dict() function
dict() function is a library function, it is used to create a dictionary with keywords( Ids) and values (s), it accepts a set of values with keywords, values and returns a dictionary.
Syntax:
dict(keyword1=value1, keyword2=value2, ...)
Parameter(s): keyword1=value1, keyword2=value2, ... – a set of keywords and values to create a dictionary.
Return value: dict – returns dictionary.
Example:
Input:
# creating dictionary
std_info = dict(name = "Amit shukla", age = 21, course = "B.Tect (CS)")
# printing the value of dictionary
print("std_info:", std_info)
Output:
std_info: {'course': 'B.Tect (CS)', 'age': 21, 'name': 'Amit shukla'}
Python code to create a dictionary
# python code to demonstrate example of
# dict() number
# creating dictionary
std_info = dict(name = "Amit shukla", age = 21, course = "B.Tect (CS)")
# printing type
print("type of std_info: ", type(std_info))
# printing the value of dictionary
print("std_info:", std_info)
Output
type of std_info: <class 'dict'>
std_info: {'course': 'B.Tect (CS)', 'age': 21, 'name': 'Amit shukla'}
TOP Interview Coding Problems/Challenges