rectangletangle
rectangletangle

Reputation: 52921

Manipulating Dictionary Values Python

I have a dictionary with the following values.

d = {'a': 0, 'b': 1, 'c': 2}

print d['c']

This would print 2.

How would I go about changing the value for a given key word? So that when the keyword 'c' was given it would return something besides 2.

Upvotes: 1

Views: 2800

Answers (1)

Blender
Blender

Reputation: 298166

Just set it using the key:

>>> d = {'a': 0, 'b': 1, 'c': 2}
>>> print d['c']
2
>>> d['c'] = 9000
>>> print d['c']
9000

Upvotes: 6

Related Questions