Python Dictionary Data Structure

Author: Al-mamun Sarkar Date: 2020-03-28 13:55:08

Python Dictionary Data Structure. The dictionary is an implementation of the hash table data structure. The following code shows how to use a dictionary in the Python programming language.

Code:

if __name__ == '__main__':
    pyt_dict = {'name': 'Mamun Sarkar', 'age': 26, 'class': 'First class'}
    print("pyt_dict['name']: ", pyt_dict['name'])
    print("pyt_dict['age']: ", pyt_dict['age'])

    pyt_dict['age'] = 8  # update existing entry
    pyt_dict['School'] = "DPS School"  # Add new entry

    print("pyt_dict['School']: ", pyt_dict['School'])
    print("pyt_dict['age']: ", pyt_dict['age'])

    del pyt_dict['name']
    print(pyt_dict)

 

Output:

pyt_dict['name']:  Mamun Sarkar
pyt_dict['age']:  26
pyt_dict['School']:  DPS School
pyt_dict['age']:  8
{'age': 8, 'class': 'First class', 'School': 'DPS School'}