Answers for "dictionary data structure python"

2

how to use dictionaries in python 3

dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
print ("dict['Name']: ", dict['Name'])
print ("dict['Age']: ", dict['Age'])
Posted by: Guest on June-04-2020
0

dictionary data structure python

#Note: you do not need to call it dictionary, however
	#A dictionary is a collection of key and value pairs that look like this
	#The element before the colon( : ) is called a key, and the element after is called a value
	#The key can be any data type and the value can be any data type
dictionary = {'key':'treasure', 1:10}

#if I wanted to retrieve the value 'treasure' i would do this
print(dictionary['key'])

#If I wanted all the keys of my dictionary I would use the .keys() method
print(dictionary.keys())

#If I wanted all the values of my dictionary I would use the .values() method
print(dictionary.values())

#If I wanted both the keys and values of my dictionary I would use .items()
print(dictionary.items())
Posted by: Guest on October-26-2021

Code answers related to "dictionary data structure python"

Python Answers by Framework

Browse Popular Code Answers by Language