函数多值返回
191 字
1 分钟
函数多值返回
函数多值返回
func foo1(a string, b int) int { fmt.Println("=====foo1=====") fmt.Println("a = ", a, "\nb = ", b) c := 100 return c}
// 多个返回值(匿名)func foo2(a string, b int) (int, int) { fmt.Println("=====foo2=====") fmt.Println("a = ", a, "\nb = ", b) return 222, 22222}
// 多个返回值(有形参名称)func foo3(a string, b int) (r1 int, r2 int) { fmt.Println("=====foo3=====") fmt.Println("a = ", a, "\nb = ", b) r1 = 321 r2 = 312 return}
// 多个返回值(有形参名称,类型相同可简写)func foo4(a string, b int) (r1, r2 int) { fmt.Println("=====foo4=====") fmt.Println("a = ", a, "\nb = ", b) r1 = 411 r2 = 412 return}
func main() { c := foo1("foo1", 111) fmt.Println("main") fmt.Println("c = ", c)
f2, f2222 := foo2("foo2", 222) fmt.Println("f2 = ", f2) fmt.Println("f2222 = ", f2222)
f3, f3333 := foo3("foo3", 333) fmt.Println("f3 = ", f3) fmt.Println("f3333 = ", f3333)
f4, f4444 := foo4("foo4", 444) fmt.Println("f4 = ", f4) fmt.Println("f4444 = ", f4444)}文章分享
如果这篇文章对你有帮助,欢迎分享给更多人!
相关文章 智能推荐
1
多态
golang 多态
2
1 变量和常量
golang 1 变量和常量
3
2 输入输出
golang 2 输入输出
4
3 基本数据类型
golang 3 基本数据类型
5
4 数组、切片和Map
golang 4 数组、切片和Map
随机文章 随机推荐