Python Modifying Values

Python Modifying Values



Modifying values

You can modify the value associated with any key in a dictionary. To do so give the name of the dictionary and enclose the key in sqaure brackets, then provide the new value for that key.

#Modifying values in a dictionary
alien_0 = {'color': 'green', 'points':5}
print(alien_0)

#change the aliein's color and point value.
alien_0['color'] = 'yellow'
alien_0['points'] = 10
print(alien_0)

Screenshot 

 

0 comments:

Post a Comment