Skip to content

Latest commit

 

History

History
18 lines (14 loc) · 641 Bytes

Basics of Dictionary.md

File metadata and controls

18 lines (14 loc) · 641 Bytes

What is a Dictionary in Python ?

Python dictionary is an unordered collection of items. It has a key: value pair. A dictionary is a python version of hash table. It is very efficient to retrieve values when the key is known.

Creating dictionary.

   dictionary = {1: 'Hello', 2: 'World'}
   dictionary = {'language' : 'python', 'versions' : [2, 3]}
   dictionary = dict([(1,'apple'), (2,'ball')])

How to access a dictionary element.

   print(my_var['Language']) #output: Python

   print(my_var.get('version')) #output: '3.6.6'