Python Dictionary is used to store the data in a key-value pair format, whereas
- Keys must be a single element
- Value can be any type such as list, tuple, integer, etc.
Syntax:-
Dict = {"Name": "Tom", "Age": 22}
Example:-
Employee = {"Name": "John", "Age": 29, "salary":25000,"Company":"GOOGLE"}
print(type(Employee))
print("printing Employee data .... ")
print("Name :",Employee["Name"])
print("Age : ", Employee["Age"])
print("Salary :", Employee["salary"])
print("Company :", Employee["Company"])
Output:-
<class 'dict'>
printing Employee data ....
Name : John
Age : 29
Salary : 25000
Company : GOOGLE
Exercises:-
- Write a py program to remove all items from the dicitionay
- Write a py program to copy one dictionary item to another
- Write a py program to print the value based on given key
- Write a py program to print all items with key-value pairs
- Write a py program to print all the keys only of a dictionary.
- Write a py program to add a dictionary item.
- Write a py program to print all the values of a dictionary.
- Write a py program to store the student records.
Comments
Post a Comment