{ ages := map[string]int { "alice": 31 , "charlie": 34 , } for k, v := range ages { if v > 33 { fmt.Println(k, v) // charlie 3 4 } } } for + range ʹ͔͚ΔͱΩʔɾΛर͏͜ͱ͕Ͱ͖Δ औΓग़͞ΕΔॱংཪଆͰγϟοϑϧ͞Ε͍ͯΔ
struct { X, Y in t } type Circle struct { Center Poin t Radius in t } func main() { c := Circle { Center: Point{X: 10, Y: 15} , Radius: 5 , } fmt.Println(c.Center.X) // 1 0 } package mai n import "fmt " type Point struct { X, Y in t } type Circle struct { Poin t Radius in t } func main() { c := Circle { Point: Point{X: 10, Y: 15} , Radius: 5 , } fmt.Println(c.X) // 1 0 } ຒΊࠐΈ ຒΊࠐΈ ແ໊ϑΟʔϧυ ʂ
Employee struct { ID in t Name strin g AnnualSalary in t } func (e Employee) MonthlySalary() int { return e.AnnualSalary / 1 2 } func main() { kato := Employee{ID: 82, Name: "Ճ౻", AnnualSalary: 3000000 } fmt.Println(kato.MonthlySalary() ) } ໊ؔͷલʹϨγʔόʔͱܕΛॻ͘ͱϝιουʹͳΔ Ϩγʔόʔ