Good day !!
Hello guys , have a recap at my previous blog . I have explained about tuples.
Previous
Context of blogs
DICTIONARIES
Operations
- Accessing
- Updating
- Deleting
- Length
Today we are going to learn about dictionaries in python . As we have got many data types(lists , tuples ... ) why still we are using dictionaries , right ?
You will have a clear idea at the end of this blog . Let's start now !!
Let me explain the disadvantages of list First . In list we cannot access the two different variables at a time . Warch this video for explanation.
Dictionaries
Dictionaries are very unique to other data types . It should be embedded in curly parenthesis "{}". It has two sections one is key and value pair . Dictionaries works on key-value pair .
Syntax
dict = {k1 : v1 , k2 : v2 , ....... }
Keys = k1,k2...........
Values = v1,v2........
Watch this for clear understanding
This is way to declare the dictionaries .
We will be going to operations in dictionaries.
Operations
Accessing the element in dictionary .
Syntax:
dict[key] # we are accessing the value
Second operation is updating a dictionary
Updating
We can update the value in pair .
Syntax
dict[k1] = Vn #Vn is new value .
Watch this video
Deleting the key - value pair
By using del function we can delete the element in dictionary
Checking the length of dictionary
By using len function we can check the length of the dictionary.
Watch this video for clear explanation
Last thing , don't forgot look at this (precaution)
Yeah , we should not enter the same key in one dictionary.
Look at this for avoiding the confusion .
Thank you for reading this blog . Hope you liked my writings.
Comments
Post a Comment