Python Dictionary Data Structure

Python Dictionary Data Structure

Instructor-svgAl-Mamun Sarkar
Mar 28 , 2020

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'}

 

  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram