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'}





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.