0% found this document useful (0 votes)
7 views

Python Lab Question 3 No Comments

Uploaded by

hhabibulla344
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Python Lab Question 3 No Comments

Uploaded by

hhabibulla344
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Aim: Write a Python program to demonstrate working with dictionaries in Python.

Algorithm:

1. Create an empty dictionary.

2. Add key-value pairs to the dictionary.

3. Access values using keys.

4. Update an existing value.

5. Delete a key-value pair.

Program:

my_dict = {}

my_dict['name'] = 'John'

my_dict['age'] = 25

my_dict['city'] = 'New York'

name = my_dict['name']

age = my_dict['age']

my_dict['age'] = 26

del my_dict['city']

print('Name:', name)

print('Age:', age)

print('Updated Dictionary:', my_dict)

Output:
Name: John

Age: 25

Updated Dictionary: {'name': 'John', 'age': 26}

You might also like