0% found this document useful (0 votes)
8 views2 pages

Dictionary

The document provides an overview of Python dictionaries, highlighting their unordered nature and key-value pair structure. It covers various operations such as creating, accessing, updating, appending, and deleting dictionary elements. Additionally, it explains how to check for membership and iterate through dictionary items.

Uploaded by

yashr0002323
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Dictionary

The document provides an overview of Python dictionaries, highlighting their unordered nature and key-value pair structure. It covers various operations such as creating, accessing, updating, appending, and deleting dictionary elements. Additionally, it explains how to check for membership and iterate through dictionary items.

Uploaded by

yashr0002323
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#Python dictionary is an unordered collection of items.

#dictionary has a key: value pair.


#Dictionary is enclosed in curly brackets{}
#Dictionaries are optimized to retrieve values when the key is known.

# Creating a Dictionary
# Dict={}
# print(Dict)
# print(type(Dict))

# Creating a Dictionary with dict() method


# Dict = dict({1: 'Python', 2: 'C++', 3:'JAVA'})
# print(Dict)

# Dict = {1: 'python', 2: 'C++', 3: 'Java'}


# print(Dict)

# accesing keys and values from a Dictionary


# print(Dict.keys())
# print(Dict.values())
# Print(Dict.items)

# accesing a element from a Dictionary


# print(Dict[2])
# print(Dict.get(3))

# Appending values in a dictionary


# Dict = {1: 'python', 2: 'C++', 3: 'Java'}
# Dict[4]='dotnet'
# print(Dict)

# Creating a Dictionary with Mixed keys


# Dict = {'Name': 'Python', 1: [1, 2, 3, 4]}
# print(Dict)

# Adding elements one at a time


#Dict={}
#Dict[0] = 'JAVA'
#Dict[2] = 'Kotlin'
#Dict[3] = 1
#print(Dict)

# Adding set of values


# to a single Key
# Dict={}
# Dict['Value_set'] = 2, 3, 4
# print(Dict)

# Updating existing Key's Value


# Dict = dict({1: 'Python', 2: 'C++', 3:'JAVA'})
# Dict[2] = 'Swift'
# print(Dict)

# accesing a element from a Dictionary


#Dict = dict({1: 'Python', 2: 'C++', 3:'JAVA'})
#print(Dict[1])
#print(Dict.get(2))
# Deleting a Key value
# using pop() method
# Dict = dict({1: 'Python', 2: 'C++', 3:'JAVA'})
# Dict.pop(2)
# print(Dict)

# using del command


# Dict = dict({1: 'Python', 2: 'C++', 3:'JAVA'})
# print(Dict)
# del Dict[2]
# print(Dict)

# Deleting entire Dictionary


#Dict = dict({1: 'Python', 2: 'C++', 3:'JAVA'})
#Dict.clear()
#print(Dict)

# membership operator 'in' 'not in'


# Dict = dict({1: 'Python', 2: 'C++', 3:'JAVA'})
# print(1 in Dict)
# print(4 not in Dict)

# Dict = {1: 'python', 2: 'C++', 3: 'Java'}


# for x in Dict:
# print(x)

# for x in Dict:
# print(Dict[x])

# for x in Dict.values():
# print(x)

# for x, y in Dict.items():
# print(x, y)

You might also like