Site icon T4Tutorials.com

Dictionary Data Type in Python

Dictionary Data Type in Python

Python’s dictionaries are dictionaries with the following properties;

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

Python Code

#!/usr/bin/python
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

Result

$python main.py
This is T4
This is Tutorials
{'dept': 'Managing', 'code': 12345, 'name': 'ayesha'}
['dept', 'code', 'name']
['Managing', 12345, 'ayesha']
Exit mobile version