Dictionary in python
Dictionaries are used to store data values in key:value pairs.
A dictionary is a collection which is changeable and does not allow duplicates.
Example of dictionary
courses={"PYTHON":"Programming","HTML":"Web Designing","SQL":"Database"}
print(courses)
Output
{'PYTHON': 'Programming', 'HTML': 'Web Designing', 'SQL': 'Database'}
Example of dictionary using key
courses={"PYTHON":"Programming","HTML":"Web Designing","SQL":"Database"}
print(courses["HTML"])
Output
Web Designing
Example of dictionary printing all keys using for loop
courses={"PYTHON":"Programming","HTML":"Web Designing","SQL":"Database"}
for i in courses:
print(i)
Output
PYTHON
HTML
SQL
HTML
SQL
Example of dictionary printing values using for loop
courses={"PYTHON":"Programming","HTML":"Web Designing","SQL":"Database"}
for i in courses:
print(courses[i])
Output
Programming
Web Designing
Database
Web Designing
Database