Python Dictionary Update method- my programming school

Python Dictionary Update method with example

 Dictionary in Python is an unordered group of data values, used to store data values like a map, which, unlike other data types that carry only a single value as an element, Python dictionary holds pair. In Python Dictionary update method updates the dictionaries with the elements from different dictionary object or from an iterable of key/value pairs.

It uses to replace what is already is used and add more data to dictionaries

Syntax:

dictionary.update(iterable)

Python dictionary update method Example 

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

OUTPUT

C:\Users\Pramod\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/Pramod/PycharmProjects/pythonProject/main.py
Before to update userinformation:{'name': 'pramod', 'age': 22, 'rollno': '17691a05b9', 'class': 'B-Tech'}
more_info={'name': 'pramod kumar yadav', 'state': 'Janakpur', 'country': 'Nepal'}
After update user information{'name': 'pramod kumar yadav', 'age': 22, 'rollno': '17691a05b9', 'class': 'B-Tech', 'state': 'Janakpur', 'country': 'Nepal'}

Process finished with exit code 0
Python Dictionary Update method

Recommend:

learn salesforce

1 thought on “Python Dictionary Update method- my programming school”

Leave a Reply

%d bloggers like this: