Start learning free

LESSON 127 OF 671 · DICTIONARIES

Updating Dictionary Values in Go

Lesson

In Go, you update a value in a map by assigning a new value to an existing key:

scores := map[string]int{}
scores["Alice"] = 95
scores["Bob"] = 87

scores["Alice"] = 99     // update: Alice is now 99
scores["Charlie"] = 72   // add new entry

The bracket operator [] both accesses and creates/updates entries. Assigning to an existing key simply overwrites the old value:

scores["Alice"] = 99  // updates Alice

Assignment
Follow the Coding Tutorial and update Alice's score to 99!


Hint
Use scores["Alice"] = 99.

STEP 1 OF 1
    Ctrl + Enter to check