Government College of Engineering and Textile Technology Berhampore
Government College of Engineering and Textile Technology Berhampore
Berhampore
NAME: SOUDIP GHOSH
SUBJECT: INTRODUCTION TO PYTHON
ROLL: 11101420026
YEAR – 3rd (6TH SEM)
DEPARTMENT: TEXTILE TECHNOLOGY
TOPIC : DICTIONARY IN PYTHON
OUTLINE OF THE PRESENTATION
I WOULD LIKE TO ACKNOWLEDGE AND GIVE MY WARMEST THNAKING TO MY TEACHER MR. ABUL
HASNAT SIR FOR GIVING ME THIS OPPORTUNITY TO WORK ON THIS PARTICULAR TOPIC AND HIS
GUIDANCE THROUGHOUT THE PROJECT HELPED ME A LOT TO COMPLETE THIS PROJECT.
Python Dictionary
Output:
{1: Hello', 2: Hii', 3: world'}
Creating a Dictionary
# Creating a Dictionary
# with Integer Keys
Dict = {1: 'Geeks', 2: 'For', 3: 'Geeks'}
print("\nDictionary with the use of Integer Keys: ")
print(Dict)
# Creating a Dictionary
# with Mixed keys
Dict = {'Name': 'Geeks', 1: [1, 2, 3, 4]}
print("\nDictionary with the use of Mixed Keys: ")
print(Dict)
Output :
Example :
# Creating an empty Dictionary
Dict = {}
print("Empty Dictionary: ")
print(Dict)
# Creating a Dictionary
# with dict() method
Dict = dict({1: 'Geeks', 2: 'For', 3: 'Geeks'})
print("\nDictionary with the use of dict(): ")
print(Dict)
# Creating a Dictionary
# with each item as a Pair
Dict = dict([(1, 'Geeks'), (2, 'For')])
print("\nDictionary with each item as a pair: ")
print(Dict)
Output :
Empty Dictionary:
print(Dict)
Output:
Example:
# Python program to demonstrate
# Creating a Dictionary
print(Dict['name'])
print(Dict[1])
Output:
Accessing a element using key:
For
There is also a method called get() that will also help in accessing the element
from a dictionary.This method accepts key as argument and returns the value.
Example:
# Creating a Dictionary
Dict = {'Dict1': {1: 'Geeks'},
'Dict2': {'Name': 'For'}}
Output:
{1: 'Geeks'} Geeks For
Dictionary methods: