标签:多个 main pre int else 类型 max 存在 span
1.函数需要定义参数的类型或者存在return的类型
func main() {
a := maxnums(2, 2)
fmt.Println(a)
}
func maxnums(a, b int) int {
if a < b {
return 1
} else {
return 2
}
}
2.多个参数和多个return
func main() {
a, b := maxnums(1, "2")
fmt.Println(a, b)
}
func maxnums(a int, b string) (int, string) {
return a, b
}
3.不需要传参和return的函数
func main() {
maxnums()
}
func maxnums() {
fmt.Println("111")
}
4.不需要传参数,需要return的函数体
func main() {
a := maxnums()
fmt.Println(a)
}
func maxnums() int {
fmt.Println("111")
return 1
}
5.需要传参但是不需要return的函数体
func main() {
maxnums(1, "2")
}
func maxnums(a int, b string) {
fmt.Println(a, b)
}
标签:多个 main pre int else 类型 max 存在 span
原文地址:https://www.cnblogs.com/Jack-cx/p/10182606.html