Menu


Notice: Undefined index: url2 in /home/u681245571/domains/studyglance.in/public_html/labprograms/pythondisplay.php on line 83

Notice: Undefined index: url3 in /home/u681245571/domains/studyglance.in/public_html/labprograms/pythondisplay.php on line 84

Notice: Undefined index: url4 in /home/u681245571/domains/studyglance.in/public_html/labprograms/pythondisplay.php on line 85

Notice: Undefined index: opurl2 in /home/u681245571/domains/studyglance.in/public_html/labprograms/pythondisplay.php on line 88

Notice: Undefined index: opurl3 in /home/u681245571/domains/studyglance.in/public_html/labprograms/pythondisplay.php on line 89

Notice: Undefined index: opurl4 in /home/u681245571/domains/studyglance.in/public_html/labprograms/pythondisplay.php on line 90

Python Programming [ Lab Programs ]


Aim:

Write a program to demonstrate working with dictionaries in python.

Source Code:

week7.py


'''Write a program to demonstrate working with dictionaries in python.'''

dict1 = {'StdNo':'532','StuName': 'Naveen', 'StuAge': 21, 'StuCity': 'Hyderabad'}
print("\n Dictionary is :",dict1)
#Accessing specific values 
print("\n Student Name is :",dict1['StuName'])
print("\n Student City is :",dict1['StuCity'])
#Display all Keys
print("\n All Keys in Dictionary ")
for x in dict1:
    print(x)
#Display all values
print("\n All Values in Dictionary ")
for x in dict1:
    print(dict1[x])
#Adding items
dict1["Phno"]=85457854
#Updated dictoinary
print("\n Uadated Dictionary is :",dict1)
#Change values
dict1["StuName"]="Madhu"
#Updated dictoinary
print("\n Uadated Dictionary is :",dict1)
#Removing Items
dict1.pop("StuAge");
#Updated dictoinary
print("\n Uadated Dictionary is :",dict1)
#Length of Dictionary
print("Length of Dictionary is :",len(dict1))
#Copy a Dictionary
dict2=dict1.copy()
#New dictoinary
print("\n New Dictionary is :",dict2)
#empties the dictionary
dict1.clear()
print("\n Uadated Dictionary is :",dict1)

Output:

image

Related Content :

Python Programming Lab Programs

1) Write a program to demonstrate different number data types in Python. View Solution

2) Write a program to perform different Arithmetic Operations on numbers in Python. View Solution

3) Write a program to create, concatenate and print a string and accessing sub-string from a given string. View Solution

4) Write a python script to print the current date in the following format “Sun May 29 02:26:23 IST 2017” View Solution

5) Write a program to create, append, and remove lists in python. View Solution

6) Write a program to demonstrate working with tuples in python. View Solution

7) Write a program to demonstrate working with dictionaries in python. View Solution

8) Write a python program to find largest of three numbers. View Solution

9) Write a Python program to convert temperatures to and from Celsius, Fahrenheit. [Formula: c/5 = f-32/9] View Solution

10) Write a Python program to construct the stars(*) pattern, using a nested for loop View Solution

11) Write a Python script that prints prime numbers less than 20. View Solution

12) Write a python program to find factorial of a number using Recursion. View Solution

13) Write a program that accepts the lengths of three sides of a triangle as inputs. The program output should indicate whether or not the triangle is a right triangle (Recall from the Pythagorean Theorem that in a right triangle, the square of one side equals the sum of the squares of the other two sides). View Solution

14) Write a python program to define a module to find Fibonacci Numbers and import the module to another program. View Solution

15) Write a python program to define a module and import a specific function in that module to another program. View Solution

16) Write a script named copyfile.py. This script should prompt the user for the names of two text files. The contents of the first file should be input and written to the second file. View Solution

17) Write a program that inputs a text file. The program should print all of the unique words in the file in alphabetical order. View Solution

18) Write a Python class to convert an integer to a roman numeral. View Solution

19) Write a Python class to implement pow(x, n) View Solution

20) Write a Python class to reverse a string word by word. View Solution