Type and the value you want to store

Your line of code might look like this:

The following example code creates a dictionary and then creates a new key, 'dracula', and gives it the value 'stoker':

>>> mydict = {'jabberwocky': 'carroll', 'sherlock holmes': 'doyle'} >>> mydict['dracula'] = 'stoker'

>>> mydict

{'jabberwocky': 'carroll', 'dracula': 'stoker'

, 'sherlock holmes':


Here, the existing key 'dracula' is given a new value, '

oldman' :

>>> mydict['dracula'] = 'oldman'

>>> mydict

{'jabberwocky': 'carroll', 'dracula': 'oldman'

1, 'sherlock holmes':


Was this article helpful?

0 0

Post a comment