Source File: ex18/main.go
package main
import (
"fmt"
)
type Animal struct {
Name string
Age int
Species string
Weight float64
}
func main() {
owners := make(map[string]Animal)
owners["Alex"] = Animal{"Doug", 5, "Dog", 25.0}
owners["Mark"] = Animal{"Catherine", 1, "Cat", 2}
owners["Debbie"] = Animal{"Gary", 1, "Goldfish", 0.1}
owners["Xan"] = Animal{"Percy", 10, "Python", 50.0}
for owner, pet := range owners {
fmt.Println(owner, "owns", pet)
}
fmt.Println("before delete", owners["Alex"])
delete(owners, "Alex")
alex, ok := owners["Alex"]
fmt.Println("after delete", alex, "is there", ok)
}