Python Adding new key-value pairs

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.

#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


python key value


1 comment:

  1. Great wrk future grow impress to see u doing a good job bst of luck good luck to u and ur team.