内容简介:命名的函数返回值可变参数:注意:其中arg是一个slice,我们可以通过arg[index]依次访问所有参数通过len(arg)来判断传递参数的个数
命名的函数返回值
func add(a, b int) (c int) { c = a + b return } func calc(a, b int) (sum int, avg int) { sum = a + b avg = (a +b)/2 return }
可变参数:
func add(arg…int) int { //0个或多个参数 } func add(a int, arg…int) int { //1个或多个参数 } func add(a int, b int, arg…int) int { //2个或多个参数 }
注意:其中arg是一个slice,我们可以通过arg[index]依次访问所有参数通过len(arg)来判断传递参数的个数
函数可以作为type:
package main import "fmt" type op_func func(int, int) int func add(a, b int) int { return a + b } func operator(op op_func, a, b int) int { return op(a, b) } func main() { fmt.Println(operator(add, 1, 2)) }
以上所述就是小编给大家介绍的《go的函数》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- Python 拓展之特殊函数(lambda 函数,map 函数,filter 函数,reduce 函数)
- Python 函数调用&定义函数&函数参数
- python基础教程:函数,函数,函数,重要的事说三遍
- C++函数中那些不可以被声明为虚函数的函数
- 017.Python函数匿名函数
- 纯函数:函数式编程入门
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Beginning ARKit for iPhone and iPad
Wallace Wang / Apress / 2018-11-5 / USD 39.99
Explore how to use ARKit to create iOS apps and learn the basics of augmented reality while diving into ARKit specific topics. This book reveals how augmented reality allows you to view the screen on ......一起来看看 《Beginning ARKit for iPhone and iPad》 这本书的介绍吧!