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工作流
树上站着一只鸟ComfyUI工作流
广阔的沙漠中矗立着一个生锈的巨大头盔
ai图片扩大comfyui工作流
一幅生动而古怪的时尚鸭子插图ComfyUI工作流
森林里一只邪恶的树妖ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

css3结合svg做一个动态广告
会议人员60s签到倒计时插件
js+css3做一个灯泡开灯关灯效果
css3搭积木叠加图形
3D立体人物效果
jquery鼠标滑过图片边框特效(jquery.focus-follow插件)
制作一个好玩的倒计时
纯css翻书效果







