且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

GO语言练习:多返回值函数

更新时间:2022-09-16 17:41:54

1、代码

GO语言练习:多返回值函数
 1 package main
 2 import (
 3     "fmt"
 4     "strconv"
 5 )
 6 
 7 func getValue(n int) (float32, string) {
 8     var x   float32 = float32(n)
 9     var str string  = strconv.Itoa(n)
10     return x, str
11 }
12 
13 func main(){
14     var n int = 10;
15 
16     x, str := getValue(n)
17 
18     fmt.Printf("x = %f\nstr = %s\n", x, str)
19 }
GO语言练习:多返回值函数

2、运行

$ go run multireturns.go
x = 10.000000
str = 10

 


本文转自郝峰波博客园博客,原文链接:http://www.cnblogs.com/fengbohello/p/4620459.html,如需转载请自行联系原作者