func 函数名(args…)返回值类型{
}
无参函数
func foo(){fmt.Println("Hello,World!")}
有参函数
func foo1(a string, b int) int {fmt.Println("a=", a)fmt.Println("b=", b)c := 100return c}
函数返回多个值
// 匿名返回多个值func foo2(a int, b int) (int, int) {a = 100b = 200return a, b}
// 返回多个值形参名称func foo3(a int, b int) (res1 int, res2 int) {// 给有返回值名称的变量赋值res1 = 1res2 = 2return}
// 如果返回值类型相同 除了最后一个参数外其他的参数都可以省略类型func foo4(a int, b int) (res1, res2 int) {// 给有返回值名称的变量赋值res1 = 1res2 = 2return}
