Python Programming Training Certification
Flexible Hours
100 Assignments
Instructor Led online Training
50 LMS Access
24X7 Support
100% Skill Level
Enquire Now
Course Overview
Python dict() Function
Python dict() function is a constructor which creates a dictionary. Python dictionary provides three different constructors to a create dictionary.
- If no argument is passed, it creates an empty dictionary.
- If a positional argument is given, a dictionary is created with the same key-value pairs. Otherwise, pass an iterable object.
- If keyword arguments are given, the keyword arguments and their values are added to the dictionary created from the positional argument.
Signature
-
dict ([**kwargs])
dict ([mapping, **kwargs])
dict ([iterable, **kwargs])
Parameters
kwargs: It is a keyword argument.
mapping: It is another dictionary.
iterable: It is an iterable object in the form of a key-value pair(s).
Return
It returns a dictionary.
Let’s see some examples of dict() function to understand it’s functionality.
Python dict() Function Example 1
A simple example to create an empty or non-empty dictionary. Arguments of the dictionary are optional.
-
# Python dict() function example
# Calling function
result = dict() # returns an empty dictionary
result2 = dict(a=1,b=2)
# Displaying result
print(result)
print(result2)
Output:
- {}
{‘a’: 1, ‘b’: 2}
Python dict() Function Example 2
-
# Python dict() function example
# Calling function
result = dict({‘x’: 5, ‘y’: 10}, z=20) # Creating dictionary using mapping
result2 = dict({‘x’: 5, ‘y’: 10, ‘z’:20})
# Displaying result
print(result)
print(result2)
Output:
- {‘x’: 5, ‘z’: 20, ‘y’: 10}
{‘x’: 5, ‘z’: 20, ‘y’: 10}
Python dict() Function Example 3
-
# Python dict() function example
# Calling function
result = dict([(1, ‘One’), [2, ‘Two’], [3,’Three’]]) # Creating using iterable
result2 = dict([[‘x’,’X’],(‘y’,’Y’)])
# Displaying result
print(result)
print(result2)
Output:
- {1: ‘One’, 2: ‘Two’, 3: ‘Three’}
{‘y’: ‘Y’, ‘x’: ‘X’}
Candidate’s Journey During Our Training Program
Expert’s Advice & Selection of Module
Choosing the right type of module for the training is half the battle & Our Team of experts will help & guide you.
Get Trained
Get Trained & Learn End to End Implementation from our Expert Trainer who are working on the same domain.
Work on Projects
We Do make our student’s work on multiple case studies , scenario based tasks & projects in order to provide real-time exposure to them.
Placements
We have a dedicated placement cell in order to provide placement assistance & relevant interviews to our candididates till selection
Placement Partner