Menu Bar

Horizontal Scrollable Menu

Search This Blog

Python Dictionary | update() method

Python Dictionary | update() method

Dictionary in Python is an unordered collection of data values, used to store data values like a map, which unlike other Data Types that hold only single value as an element, Dictionary holds key : value pair.
In Python Dictionary, update() method updates the dictionary with the elements from the another dictionary object or from an iterable of key/value pairs.
It use to replace which is already is used and add more data into dictionary

EXAMPLE
print(f'Before to update userinformation: 
{user_info}')

OUTPUT

Before to update userinformation: {'name': 'pramod
', 'age': 22, 'rollno': '17691a05b9', 
'class': 'B-Tech'}
more_info={'name':'pramod kumar yadav','state':
 'Janakpur','country':'Nepal'}
user_info.update(more_info)
print(f'After update user information{user_info}')

OUTPUT

After update user information {'name': 
'pramod kumar yadav', 'age': 22, 'rollno': 
'17691a05b9', 'class': 'B-Tech', 'state': 
'Janakpur', 'country': 'Nepal'}

No comments:

ads3