Go语言中支持:函数、匿名函数和闭包定义函数使用func关键字func 函数名(参数)(返回值){函数体
}注意:函数名由字母、数字、下划线组成,但不能以字母开头。在同一个包内,函数名不能重名//求两个数的和
func sumFn(x int, y int) int {sum := x + yreturn sum
}func main(){result := sumFn(12, 3)fmt.Println(result)//15
}函数参数的简写(只能简写前面的)func subFn(x, y int)
从 C++ 转 Go 后,当操作时间变量的时候,Go 原生的 time 包用起来简直不要太舒服,再也不用自己写轮子了。我之前就写过一篇文章介绍了 time 的常用用法。不过在开发过程中其实也遇到 time 在 AddDate 的一个坑,因此撰此薄文分享一下。问题发现AddDate 有三个参数,分别是年、月、日。在官方文档中,对 time.AddDate 方法的说明如下:AddDate returns the time corresponding to adding the given number of
Go+Python双语言混合开发V:ititit111222333 * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on a