Course Content

If you are facing any issue in playing video please use Firefox browser.

Course Content

Description

What is Python Dictonaries ?

 

In this lecture we will see that,

What is dictionary?

Which are the different operations of dictionary?

How to implement dictionary with all its functions?

 

Dictionary is also used to store data like list and tuples.

 

Each key separated from its value by a colon (:), the items are separated by commas, and the whole thing is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this - { }

 

Keys are unique within a dictionary while values may not be.

 

The values of a dictionary can be of any type.

 

Example :

dict={'Name':'Zara','Age':7,'Class':'First'}

 

Accessing values in dictionary

 

dict={'Name':'Vern','Age':7,'Class':'First'}

 

print("dict['Name']:",dict['Name'])

print("dict['Age']:",dict['Age'])

 

Updating dictionary

 

dict={'Name':'Vern','Age':7,'Class':'First'}

 

dict['Age']=8;

dict['School']="DPS School";

print "dict['Age']:",dict['Age']

print "dict['School']:",dict['School']

 

Delete dictionary elements

 

dict={'Name':'Vern','Age':7,'Class':'First'}

 

del dict['Name'];

dict.clear();

del dict;

print("dict['Age']:",dict['Age'])

 

Properties of dictionary keys

 

More than one entry per key not allowed. Which means no duplicate key is allowed. When duplicate keys encountered during assignment, the last assignment wins.

 

Keys must be immutable. Which means you can use strings, numbers or tuples as dictionary keys bus something like ['key'] is not allowed.

 

Dictionary function

 

dir(nameofdictionary)

help(nameofdictionary.functionname)

 

student1={'name':'Nirmal','Age':23,'email':'nirmal@gmail.com'}

print(student1)

print(student1['Name'])

print(student1['Age'])

print(student1['email'])

Output :

{'name':'Nirmal','Age':23,'email':'nirmal@gmail.com'}

Nirmal

23

nirmal@gmail.com

 

 

FAQs

Share With Friend

Have a friend to whom you would want to share this course?

Download The Apps

Code Scan or Download the app
Google Play Store
297K+ Downloads
4.5 Rating
10K+ Reviews
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere