Go 맵

1 개요[ | ]

Go Map
Go 맵
package main

import "fmt"

func main() {
	var m = map[string]int{
		"x": 40,
		"y": -74,
	}
	fmt.Println(m)
	fmt.Println(m["x"])
	fmt.Println(m["y"])
}
package main

import "fmt"

func main() {
	var m = map[string]interface{}{}
	m["x"] = 40.68433
	m["y"] = -74.39967
	m["name"] = "Bell Labs"
	fmt.Println(m)
}
package main

import "fmt"

type Vertex struct {
	Lat, Long float64
}

func main() {
	var m = make(map[string]Vertex)
	m["Bell Labs"] = Vertex{
		40.68433, -74.39967,
	}
	fmt.Println(m["Bell Labs"])
}

2 foreach[ | ]

package main

import "fmt"

func main() {
	var m = map[string]int{
		"x": 40,
		"y": -74,
	}
	for k, v := range m {
		fmt.Println("key:", k, "=> value:", v)
	}
}

3 같이 보기[ | ]

4 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}