Dictionary Data Type in Python

Dictionary Data Type in Python

Python’s dictionaries are dictionaries with the following properties;

  • Having kind of hash table type
  • Work like associative arrays
  • ¬†Work like hashes found in Perl
  • ¬†contains key-value pairs.

A dictionary key type can be of any type but most key types are numbers or strings.

Python Code

dict = {}
dict['T4'] = "This is T4"
dict['Tutorials'] = "This is Tutorials"
tinydict = {'name': 'ayesha','code':12345, 'dept': 'Managing'}
print dict['T4'] # Prints value for 'T4' key
print dict['Tutorials'] # Prints value for Tutorials key
print tinydict # Prints complete dictionary
print tinydict.keys() # Prints all the keys
print tinydict.values() # Prints all the values


$python main.py
This is T4
This is Tutorials
{'dept': 'Managing', 'code': 12345, 'name': 'ayesha'}
['dept', 'code', 'name']
['Managing', 12345, 'ayesha']
Prof.Fazal Rehman Shamil (Available for Professional Discussions)
1. Message on Facebook page for discussions,
2. Video lectures on Youtube
3. Email is only for Advertisement/business enquiries.