Skip to content

Instantly share code, notes, and snippets.

@ishankhare07
Last active November 9, 2017 08:28
Show Gist options
  • Save ishankhare07/af5576d844bd13d8a0487b9a7815ceb4 to your computer and use it in GitHub Desktop.
Save ishankhare07/af5576d844bd13d8a0487b9a7815ceb4 to your computer and use it in GitHub Desktop.
a = {}
# add a key-value pair
a['name'] = 'ishan'
# lets see whats in there
print(a)
# {'name': 'ishan'}
# add more key-value pairs
a['age'] = 23
a['gender'] = 'male'
print(a)
# {'gender': 'male', 'age': 23, 'name': 'ishan'}
# note above that the keys are not in the same order as we entered them,
# this is because python's dictionaries are unordered
# see https://stackoverflow.com/a/15479974/2972348
# get a specific value
print(a['name'])
# 'ishan'
# let's update a value
a['age'] = 24
print(a)
# {'gender': 'male', 'age': 24, 'name': 'ishan'}
# let's delete some values
del a['age']
print(a)
# {'gender': 'male', 'name': 'ishan'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment