Dictionary

#!/usr/bin/evn python

# Make a dictionary
dataDic = {'Sam' : 'programmer',
           'Jack' : 'graphics designer',
           'Robert' : 'background artist',
           'James' : 'game developer'}

print (dataDic)

# Add new entry
dataDic['Toby'] = 'video editor'
print ('\n\nAfter inserting an entry', dataDic)

# Update existing entry
dataDic['Robert'] = 'vector artist'
print ('\n\nAfter update an entry', dataDic)

# Remove entry with key 'James'
del dataDic['James']
print ('\n\nAfter delete an entry', dataDic)

# Remove all entries in dataDic
dataDic.clear()
print ('\n\nAfter clearing all entry', dataDic)

# Delete entire dictionary
del dataDic



#***** Output *****  
{'Sam': 'programmer', 'Jack': 'graphics designer', 'Robert': 'background artist', 'James': 'game developer'}


After inserting an entry {'Sam': 'programmer', 'Jack': 'graphics designer', 'Robert': 'background artist', 'James': 'game developer', 'Toby': 'video editor'}


After update an entry {'Sam': 'programmer', 'Jack': 'graphics designer', 'Robert': 'vector artist', 'James': 'game developer', 'Toby': 'video editor'}


After delete an entry {'Sam': 'programmer', 'Jack': 'graphics designer', 'Robert': 'vector artist', 'Toby': 'video editor'}


After clearing all entry {}

Recommended for you