From 21c588354c88b309408b81e738efc6829c9b9c5b Mon Sep 17 00:00:00 2001 From: Mi-Br <43519102+Mi-Br@users.noreply.github.com> Date: Fri, 17 May 2024 15:28:58 +0200 Subject: [PATCH] [go/en] missing map keys (#4413) --- go.html.markdown | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/go.html.markdown b/go.html.markdown index b93cbc61..81d45b98 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -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.