Golang学习[函数]

函数的结构如下

func(p mytype) funcname(q int)(r,s int){return 0,0}

函数有很多特点


多值返回

Go可以返回多值

延迟代码

在defer后指定函数会在退出的时候调用

func ReadWrite() bool {
   file.Open("fileName")
   defer file.Close()
   //....
}

变参

func myfunc(arg ...int){
}

回调

func callback(y int,f func(int)){
	f(y)
}


你可能感兴趣的:(golang,go语言)