惜风不起、唯有努力!
golang中return简单使用

golang中return简单使用

func funcs01 (age int) string {
	name := "tom"
	fmt.Printf("我今年%d岁,",age)
	return name
}

func funcs02 (yuwen_fraction float64, yingyu_fraction float64, shuxue_fraction float64) float64{
	total := yuwen_fraction + yingyu_fraction + shuxue_fraction
	fmt.Printf("考生tom成绩如下\n语文考试分数: %v\n数学考试分数: %v\n英语考试分数: %v\n",yuwen_fraction,shuxue_fraction,yingyu_fraction)
	return total
}

func funcs03 (x1 int, x2 int) (int,int,string) {
	x := x1 + x2
	s := x1 - x2
	name := "xiaom"
	return x, s, name

}

func main()  {
	name := funcs01(20)
	fmt.Printf("我的名字叫: %s\n",name)

	total := funcs02(80.5,65.5,90.5)
	fmt.Printf("tom is 语数英总分为:%v",total)

	res01, res02, name := funcs03(90,66)
	fmt.Printf("%s is: %v and %v\n",name,res01,res02)

}

发表回复

您的电子邮箱地址不会被公开。