package main
import "fmt"
type Book struct { //这是自定义数据类型----结构体(struct)
title string
author string
page int
}
func printBooks(book *Book) {
fmt.Printf("书名:%s,作者:%s,页数:%d \n", book.title, book.author, book.page)
}
func creatMap() {
student := map[string]int{ //这是map数据类型 无序类型
"张三": 90, "李四": 50, "王五": 66, "二麻子": 77,
}
fmt.Println(student)
sss := make(map[string]string, 10) //capaCity = 10 初始容量
sss["李宁"] = "大陆"
fmt.Println(sss)
ssr := make(map[string][]int) //单Key多Value
ssr["李宁"] = []int{1, 2, 3, 4, 5}
fmt.Println(ssr)
}
func main() {
PythonBook := Book{"Python入门", "伍某", 500}
bbb := [...]int{1, 2, 3, 4, 5, 9}
fmt.Println(len(bbb))
printBooks(&PythonBook)
creatMap() //执行创建map函数
}
Go语言自定义数据类型与map类型
最新推荐文章于 2024-05-07 20:10:40 发布