Go Maps: Difference between revisions
Jump to navigation
Jump to search
Line 28: | Line 28: | ||
Indexing operator <tt>[[Go Concepts - Operators#.5B.5D|[]]]</tt> returns the value corresponding to the specified key. If the key does not exist, the [[Go Concepts - The Type System#Zero_Value|zero value]] for the value type is returned. | Indexing operator <tt>[[Go Concepts - Operators#.5B.5D|[]]]</tt> returns the value corresponding to the specified key. If the key does not exist, the [[Go Concepts - The Type System#Zero_Value|zero value]] for the value type is returned. | ||
The indexing operator can be also used to assign a value to a key. |
Revision as of 02:30, 28 March 2016
Internal
Overview
A map is an unordered collection of key-value pairs.
Declaration
Long Declaration
var map_identifier map[key_type]value_type
Example of a map of string to ints:
var m map[string]int
Short Declaration
Map Operators and Functions
Indexing Operator
Indexing operator [] returns the value corresponding to the specified key. If the key does not exist, the zero value for the value type is returned.
The indexing operator can be also used to assign a value to a key.