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
Recommend:
- Python Count char in String
- Python Last Character from String
- Python Odd and Even | if the condition
- Python Greater or equal number
- Python PALINDROME NUMBER
- Python FIBONACCI SERIES
- Python Dictionary | Items method | Definition and usage
- Python Dictionary | Add data, POP, pop item, update method
- Python Dictionary | update() method
- Delete statement, Looping in the list In Python
- Odd and Even using Append in python
- Python | Simple Odd and Even number
learn salesforce
1 thought on “Python Dictionary Update method- my programming school”