Python Adding new key-value pairs
Adding new key-value pairs
You can store as many key-value pairs as you want in a dictionary, until your computer runs out of memory. To add a new key-value pair to an existing dictionary give the name of the dictionary and the new key in square brackets, and set it equal to the new value.
This also allows you to start with an empty dictionary and add key-value pairs as they become relevant.
You can store as many key-value pairs as you want in a dictionary, until your computer runs out of memory. To add a new key-value pair to an existing dictionary give the name of the dictionary and the new key in square brackets, and set it equal to the new value.
This also allows you to start with an empty dictionary and add key-value pairs as they become relevant.
#Adding a key-value pair alien_0 = {'color': 'green', 'points':5} alien_0['x'] = 0 alien_0['y'] = 25 alien_0['speed'] = 1.5 #Adding to an empty dictionary alien_0 = {} alien_0['color'] = 'green' alien_0['points'] = 5 print(alien_0)
No comments:
Post a Comment