首页 > 其他分享 >0085-Go-多返回值函数

0085-Go-多返回值函数

时间:2022-10-30 08:35:31浏览次数:77  
标签:int fmt Println values 返回值 Go 0085 main

环境

  • Time 2022-08-23
  • Go 1.19

前言

说明

参考:https://gobyexample.com/multiple-return-values

目标

使用 Go 语言的函数,返回两个值。

直接返回

package main

import "fmt"

func values() (int, int) {
    return 3, 7
}

func main() {

    a, b := values()
    fmt.Println(a)
    fmt.Println(b)

    _, c := values()
    fmt.Println(c)
}

命名返回

package main

import "fmt"

func values() (a int, b int) {
    a = 7
    b = 3
    return
}

func main() {

    a, b := values()
    fmt.Println(a)
    fmt.Println(b)

    _, c := values()
    fmt.Println(c)
}

总结

使用 Go 语言的函数,返回两个值。

附录

标签:int,fmt,Println,values,返回值,Go,0085,main
From: https://www.cnblogs.com/jiangbo4444/p/16840454.html

相关文章

  • 0086-Go-可变参数函数
    环境Time2022-08-23Go1.19前言说明参考:https://gobyexample.com/variadic-functions目标使用Go语言的可变参数函数。可变参数函数packagemainimport"fm......
  • 0087-Go-闭包
    环境Time2022-08-23Go1.19前言说明参考:https://gobyexample.com/closures目标使用Go语言的闭包。示例packagemainimport"fmt"funcintSeq()func()i......
  • 0088-Go-递归
    环境Time2022-08-23Go1.19前言说明参考:https://gobyexample.com/closures目标使用Go语言的递归。递归函数packagemainimport"fmt"funcfact(nint)i......
  • 0089-Go-指针
    环境Time2022-08-23Go1.19前言说明参考:https://gobyexample.com/pointers目标使用Go语言的指针。示例packagemainimport"fmt"funczeroval(ivalint)......
  • 0090-Go-字符串
    环境Time2022-08-23Go1.19前言说明参考:https://gobyexample.com/strings-and-runes目标使用Go语言的字符串。字节遍历packagemainimport"fmt"funcma......
  • 0091-Go-结构体
    环境Time2022-08-24Go1.19前言说明参考:https://gobyexample.com/structs目标使用Go语言的结构体。直接使用结构体packagemainimport"fmt"typeperson......
  • 0092-Go-方法
    环境Time2022-08-24Go1.19前言说明参考:https://gobyexample.com/methods目标使用Go语言的方法。值方法packagemainimport"fmt"typerectstruct{......
  • 0093-Go-接口
    环境Time2022-08-24Go1.19前言说明参考:https://gobyexample.com/interfaces目标使用Go语言的接口。定义接口typegeometryinterface{area()float64......
  • 0094-Go-结构体嵌入
    环境Time2022-08-24Go1.19前言说明参考:https://gobyexample.com/struct-embedding目标使用Go语言的结构体嵌入。定义结构体typebasestruct{numint......
  • 0095-Go-泛型
    环境Time2022-08-24Go1.19前言说明参考:https://gobyexample.com/generics目标使用Go语言的泛型。泛型函数packagemainimport"fmt"funcMapKeys[Kcom......