Maps are Go’s built-in associative data type (sometimes called hashes or dicts in other languages). |
|
|
|
|
|
|
|
To create an empty map, use the builtin |
|
Set key/value pairs using typical |
|
Printing a map with e.g. |
|
Get a value for a key with |
|
If the key doesn’t exist, the zero value of the value type is returned. |
|
The builtin |
|
The builtin |
|
To remove all key/value pairs from a map, use
the |
|
The optional second return value when getting a
value from a map indicates if the key was present
in the map. This can be used to disambiguate
between missing keys and keys with zero values
like |
|
You can also declare and initialize a new map in the same line with this syntax. |
|
The |
|
Note that maps appear in the form |
|
Next example: Functions.