計算機科学のブログ

labeling data - Maps - make, literals

Head First GoJay McGavren(著)、O’Reilly Media)の Chapter 7(labeling data - Maps)、p.214(Exercise)の解答を求めてみる。

コード

main.go

package main

import "fmt"

func main() {
	jewelry := make(map[string]float64)
	jewelry["necklace"] = 89.99
	jewelry["earrings"] = 79.99
	clothing := map[string]float64{"pants": 59.99, "shirt": 39.99}
	fmt.Println("Earrings:", jewelry["earrings"])
	fmt.Println("Necklace:", jewelry["necklace"])
	fmt.Println("Shirt:", clothing["shirt"])
	fmt.Println("Pants", clothing["pants"])
}

入出力結果(Terminal, Zsh)

% go run ./main.go 
Earrings: 79.99
Necklace: 89.99
Shirt: 39.99
Pants 59.99
%