Learning Day-08 ( 01-July-2020 )

** Next Hands-on Session will be on 04-July-2020 Stay Tuned....

Let's Learn Python

# Day-08

Deep Dive into Dictionaries -01

Dictionary:
A dictionary is a collection which is unordered, changeable and indexed. In Python dictionaries are written with curly brackets, and they have keys and values.

# Below are some of the Operations @ Dictionaries.


student={"name": "abc", "rollnumber":"1234", "branch":"cse"}
print(student)
print(type(student))

Output: 

{'name': 'abc', 'rollnumber': '1234',
'branch': 'cse'}
<class 'dict'>


# To find the Length of the Dictionary:
print(len(student))

Output: 3

#Finding the total items in the Dictionary:
student.items()
print(student)
OUtput:
{'name': 'abc', 'rollnumber': '1234',
'branch': 'cse'}

#keys
d1=student.keys()
print(d1)
Output:
dict_keys(['name',
'rollnumber', 'branch'])

#items()
d1=student.items()
print(d1)
Output:
dict_items([('name', 'abc'),
('rollnumber', '1234'),
('branch', 'cse')])

#pop() # To delete an Element in the List
student.pop('branch')
print(student)
Output:
{'name': 'abc',
'rollnumber':'1234'}

#values # To know the Values 
student.values()
print(student)
Output:
{'name': 'abc',
'rollnumber': '1234'}


#index() # To Find the Index value of an item.
print(student['rollnumber'])
print(student['name'])
Output:
1234 abc


#clear() # To clear the Entire Data
student.clear()
print(student)
Output:
{}

Likewise we will perform many
Operations @ Dictionary

To Download This Material
please click on the below link:



Thank you so much for your Valuable time




Comments