Basic Programs

If Else Programs

While loop Programs

For loop Programs

List Programs

Dict Programs


Python program to Change the items in dictionary


In this example shows, the simple method is used to change the items in dictionary using the update() method.

Example.py

dict = {'name' : 'Alex', 'age' : 24, 'status':'single', 'mobile':8987641385}

# printing the dictionary
print("Dictionary \'dict\' is...")
print(dict)

# updating the values 
dict['name'] = 'Trispan Alex'
dict['age'] = 26
dict['status'] = 'Married'

# after changing the values
print("Updated Dictionary \'dict\' is...")
print(dict)

Output

Dictionary 'dict' is...
{'name': 'Alex', 'age': 24, 'status': 'single', 'mobile': 8987641385}

Updated Dictionary 'dict' is...
{'name': 'Trispan Alex', 'age': 26, 'status': 'Married', 'mobile': 8987641385}

Prev Next