Dictionary in Python:-
it is used to store data using key: value pair, the key is used to provide identity and value is used to represent data.
Syntax
var = {'key':value,'key':value,'key':value}
student= {'rno':1001,'sname':"manish",'branch':"cs",'fees':45000}
print(student['rno'])
Dictionary provides a mutable object that means we can add, edit, and delete dictionary elements.
1) update():- this method will add elements if the key does not exist otherwise update data.
student.update({'key':value})
2 delete():- it is used to remove any data from the dictionary
del(student['rno'])
Complete Program Explanation of Dictionary:-
student= {'rno':1001,'sname':"manish",'branch':"cs",'fees':45000}
student.update({'sem':'vth'})
del(student['rno'])
for key in student:
print(key + "---->" + str(student[key]))
print(student.keys())
print(student.values())
print(len(student))
ASSIGNMENT OF DICTIONARY:-
WAP to reverse dictionary elements?
WAP to find max key and max value in Dictionary?
WAP to count total integer, string, and float value in the dictionary?
WAP to create a dictionary to store five employee record using "empid","empname","job" and "salary
"?
Syntax
var = {'key':value,'key':value,'key':value}
student= {'rno':1001,'sname':"manish",'branch':"cs",'fees':45000}
print(student['rno'])
Dictionary provides a mutable object that means we can add, edit, and delete dictionary elements.
1) update():- this method will add elements if the key does not exist otherwise update data.
student.update({'key':value})
2 delete():- it is used to remove any data from the dictionary
del(student['rno'])
Complete Program Explanation of Dictionary:-
student= {'rno':1001,'sname':"manish",'branch':"cs",'fees':45000}
student.update({'sem':'vth'})
del(student['rno'])
for key in student:
print(key + "---->" + str(student[key]))
print(student.keys())
print(student.values())
print(len(student))
ASSIGNMENT OF DICTIONARY:-
WAP to reverse dictionary elements?
WAP to find max key and max value in Dictionary?
WAP to count total integer, string, and float value in the dictionary?
WAP to create a dictionary to store five employee record using "empid","empname","job" and "salary
"?
POST Answer of Questions and ASK to Doubt