Python Dictionary Tutorial

  • date 17th July, 2019 |
  • by Prwatech |
  • 0 Comments

 

Python Dictionary Tutorial for Beginners

 

Welcome to the world of Python Dictionary Tutorial. Are you the one who is looking forward to knowing the Python Dictionary Tutorial? Or the one who is very keen to explore the Python Dictionary with Examples that are available? Then you’ve landed on the Right path which provides the standard information of Python Dictionary.

 

Here, we will learn about Dictionary in Python Programming language with examples and its different methods. Dictionary in Python Programming language is a special type of variable that includes a pair of items, keys, values and unordered collection of items. Do you want to know about Introduction to Dictionaries in Python with examples, then just follow the below mentioned Python Dictionary tutorial for Beginners from Prwatech and take advanced Python training like a Pro from today itself under 10+ years of hands-on experienced Professionals.

 

Introduction to Dictionaries in Python

 

A dictionary in Python Programming Language is a collection of unordered, immutable, indexed having key-value pair kind of elements enclosed by curly braces.

 

Python Dictionary Examples

 

Ex)    c = { 1: “aa”, 2: “bba”, 3: “ab”, 4: “ba”}

You can access an element of a dictionary by referring to its key name, inside square brackets.

Ex)    c = { 1: “aa”, 2: “bba”, 3: “ab”, 4: “ba”}

print(c[2])
You can change the v

alue of a specific element by referring to its key name:

Ex)    c = { 1: “aa”, 2: “bba”, 3: “ab”, 4: “ba”}
c[1] : “ww”
print(c)

 

 

 

You can traverse through a dictionary using for loop

Ex)    c = { 1: “aa”, 2: “bba”, 3: “ab”, 4: “ba”}
for x in c:
print(x)

Python Dictionary Methods

 

get():

 

It is used to get the value from the key in a dictionary.

Ex)    c = { 1: “aa”, 2: “bba”, 3: “ab”, 4: “ba”}
print(c.get(2)

 

values():

 

It is used to print all the values from the dictionary.

Ex)    c = { 1: “aa”, 2: “bba”, 3: “ab”, 4: “ba”}
for x in c.values()
print(x)

 

items():

 

It is used to traverse through the dictionary to print both key and values together.

Ex)    c = { 1: “aa”, 2: “bba”, 3: “ab”, 4: “ba”}
for x,y in c.items():
print(c[2])

 

len():

It is used to determine the total number of elements in the dictionary.

Ex)    c = { 1: “aa”, 2: “bba”, 3: “ab”, 4: “ba”}
print(len(c))

 

pop():

It is used to delete a value with the specified key in a dictionary.

Ex)    c = { 1: “aa”, 2: “bba”, 3: “ab”, 4: “ba”}
print(c.pop(2))

 

popitem():

 

It is used to delete the last inserted element from a dictionary.

Ex)    c = { 1: “aa”, 2: “bba”, 3: “ab”, 4: “ba”}
print(c.popitem())

 

del():

 

It is used to delete an entire dictionary.

Ex)    c = { 1: “aa”, 2: “bba”, 3: “ab”, 4: “ba”}
c.del()

 

copy():

 

It is used to create a copy of a dictionary.

Ex)    c = { 1: “aa”, 2: “bba”, 3: “ab”, 4: “ba”}
x=c.copy()
print(x).

 

We hope you understand Python Dictionary Tutorial for Beginner’s concepts. Get success in your career as a Python Developer by being a part of the Prwatech, India’s leading Python training institute in Bangalore.

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Quick Support

image image