This is a created article in which the information may have evolved or changed.
function is the core of go, and we will learn about functions through a number of different examples.
Package Mainimport "FMT" //This function inputs two int data, calculates and returns the int type and the Func plus (a int, b int) int { //GO need to return the value explicitly using the return statement It does not automatically return the value of the last expression in the function. return a + b}func main () { //As you would think, call the function res through "name (args)" : = Plus (1, 2) FMT. Println ("1+2 =", res)}
Output
$ go Run functions.go 1+2 = 3
The functions of the go language also have some other functions. One of these is the multi-valued return that will be learned in the next section.
Next example: Go by Example:multiple Return Values.
English original