make_maps.go 716 B

12345678910111213141516171819202122232425262728
  1. package main
  2. import "fmt"
  3. func main() {
  4. var mapLit map[string]int
  5. //var mapCreated map[string]float32
  6. var mapAssigned map[string]int
  7. mapLit = map[string]int{"one": 1, "two": 2}
  8. mapCreated := make(map[string]float32)
  9. mapAssigned = mapLit
  10. mapCreated["key1"] = 4.5
  11. mapCreated["key2"] = 3.14159
  12. mapAssigned["two"] = 3
  13. fmt.Printf("Map literal at \"one\" is: %d\n", mapLit["one"])
  14. fmt.Printf("Map created at \"key2\" is: %f\n", mapCreated["key2"])
  15. fmt.Printf("Map assigned at \"two\" is: %d\n", mapLit["two"])
  16. fmt.Printf("Map literal at \"ten\" is: %d\n", mapLit["ten"])
  17. }
  18. /* Output:
  19. Map literal at "one" is: 1
  20. Map created at "key2" is: 3.141590
  21. Map assigned at "two" is: 3
  22. Map literal at "ten" is: 0
  23. */