You can
define a map in literal notation also.
Syntax
mapName :=
map[dataType1]dataType2{
key1 : value1,
key2 : value2,
.....
.....
.....
keyN : valueN
}
App.go
package main import "fmt" func main() { employees := map[int]string{ 1: "Krishna", 2: "Ram", //Must have trailing comma } fmt.Println("Map with two elements : ", employees) }
Output
Map with
two elements : map[1:Krishna 2:Ram]
No comments:
Post a Comment