go语言有哪些函数,下面web建站小编给大家简单介绍go语言支持哪些函数?
函数定义
func sayHello() {
fmt.Println("你好!")
}
函数作为返回值
func do(s string) (func(int, int) int, error) {
switch s {
case "+":
return add, nil
case "-":
return sub, nil
default:
err := errors.New("无法识别的操作符")
return nil, err
}
}
func main() {
// 将匿名函数保存到变量
add := func(x, y int) {
fmt.Println(x + y)
}
add(10, 20) // 通过变量调用匿名函数
//自执行函数:匿名函数定义完加()直接执行
func(x, y int) {
fmt.Println(x + y)
}(10, 20)
}
func calc(base int) (func(int) int, func(int) int) {
add := func(i int) int {
base += i
return base
}
sub := func(i int) int {
base -= i
return base
}
return add, sub
}
func main() {
f1, f2 := calc(10)
fmt.Println(f1(1), f2(2)) //11 9
fmt.Println(f1(3), f2(4)) //12 8
fmt.Println(f1(5), f2(6)) //13 7
}
上面是“简单介绍go语言支持哪些函数”的全面内容,想了解更多关于 后端开发 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_2846.html
workflows工作流
一群可爱的小老鼠ComfyUI工作流
一把令人难忘的美丽吉他ComfyUI工作流
一只蚊子被嵌在琥珀中ComfyUI工作流
Latent放大comfyui工作流
树枝上一只色彩斑斓的小鸟
森林里有一个皮肤像抛光黑曜石的生物
庭院,彩色玫瑰,云雾笼罩comfyui工作流
五彩斑斓的蛇状飞鸟
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

canvas空间文本射线
3d文字动画效果
如何利用css3+js做一个下雨效果
用svg画出游泳池动画效果
纯css制作卡通头像(随鼠标转头)
SVG路径动画效果
3d空间行走效果







