This is a creation in Article, where the information may have evolved or changed.
The go language has revolutionized the ability to provide multiple return values in the static development language camp. This feature allows developers to free themselves from the pain of returning multiple values in a variety of awkward ways, without having to differentiate which of the parameter lists to use for input, which are used for output, or to specifically define a data structure just to return multiple values.
Package <textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">Mainimport "FMT" func vals (int, int) {return 3, 7}func main () {A, B: = Vals () fmt. Println (a) fmt. Println (b) _, C: = Vals () fmt. Println (c)}</textarea>
| 123456789101112131415 |
Package MainImport "FMT"funcVals() (int, int) { return 3, 7}funcMain() { a, b := Vals() FMT.Println(a) FMT.Println(b) _, C := Vals() FMT.Println(C)} |
Package <textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">main Import "FMT" func split (sum int) (x, y int) {x = sum * 4/9 y = sum-x return} func main () { Fmt. Println (split)}</textarea>
| 12345678910111213 |
Package Main Import "FMT" funcSplit(sumint) (x, y int) { x = sum * 4/9 y = sum - x return} funcMain() { FMT.Println(Split( -))} |
go multiple return values