
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to update the value of a key in a dictionary in Python?
Python dictionary object is an unordered collection of key:value pairs. Ina dictionary object d, the value associated to any key can be obtained by d[k].
>>> d={'one':1, 'two':2,'three':3,'four':4} >>> d['two'] 2
The assignment d[k]=v will update the dictionary object. If existing key is used in the expression, its associated value will be updated. If the key has not been used, a new key-value pair will be added in the dictionary object.
>>> d={'one':1, 'two':2,'three':3,'four':4} >>> d['two']=22 >>> d {'one': 1, 'two': 22, 'three': 3, 'four': 4} >>> d['five']=5 >>> d {'one': 1, 'two': 22, 'three': 3, 'four': 4, 'five': 5}
- Related Articles
- Accessing Key-value in a Python Dictionary
- C++ Program to Update value of Dictionary using key
- Add a key value pair to dictionary in Python
- How to update the value stored in a Dictionary in C#?
- Python Program to print key value pairs in a dictionary
- How to print a value for a given key for Python dictionary?
- How to get a value for a given key from a Python dictionary?
- How to update a Python dictionary values?
- How to update value of a key in a list of a json in MongoDB?
- Get key from value in Dictionary in Python
- How to check if a key exists in a Python dictionary?
- How to remove a key from a python dictionary?
- Finding The Biggest Key In A Python Dictionary?
- Get key with maximum value in Dictionary in Python
- How to extract subset of key-value pairs from Python dictionary object?

Advertisements