This is a created article in which the information may have evolved or changed.
Package main//define current packages name
Import "FMT"
Import "math"//above can be merged into import ("FMT" "math")
Func Main () {
Fmt. Println ("Hello", Math.) Pi, "World"); The first letter will be exported from the package, the other symbols are not visible.
}
The func add (a int, b int) int {//parameter type is placed after the parameter name, the return value type is put to the last, and the same parameter type can even be specified at the last same type declaration.
return a + B;
}
function can return any number of return values
Func Swap (A, B string) (string, String) {//return value to be enclosed in parentheses
return B, A;
}
Func split (sum int) (a int, b int) {//Name return value, return can not be specified
A = SUM/2;
b = Sum * 2;
Return
}