Skip to content

Commit

Permalink
[go/en] missing map keys (#4413)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mi-Br authored May 17, 2024
1 parent c268b08 commit 21c5883
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions go.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ can include line breaks.` // Same string type.
// hash or dictionary types of some other languages.
m := map[string]int{"three": 3, "four": 4}
m["one"] = 1
// Looking up a missing key returns the zero value,
// which is 0 in this case, since it's a map[string]int
m["key not present"] // 0
// Check if a key is present in the map like this:
if val, ok := m["one"]; ok {
// Do something
}

// Unused variables are an error in Go.
// The underscore lets you "use" a variable but discard its value.
Expand Down

0 comments on commit 21c5883

Please sign in to comment.