This is a creation in Article, where the information may have evolved or changed.
1.Go programs are made up of packages. The entry that runs the program is the package main. The program uses and imports the package "FMT". The Go Language compilation runtime (go Run Xxx.go), the file must have the main package and the main function to run.
Package Mainimport ("FMT") func main () {FMT. Println ("hello!"))}
2. Function can have no parameters or accept multiple parameters
Func Add (x int, y int) int { return x + y}func Add (x, y int) int {return x + Y}func main () { fmt. Println (Add (1, 2))}
Func swap (x, y String) (string, string) {return y, X}func main () {A, B: = Swap ("Hello", "World") fmt. Println (A, B)}
Func split (sum int) (x, y int) {x = sum * 4/9 y = sum-x return}
Add Accept two + int the parameters of the type. ( Note that the type is after the variable name .) )
with no parameters return statement returns the current value of the result. i.e. ' direct ' return //func split return y
The 3.var statement defines a list of variables, like the argument list for a function, the type is behind
var c, Python, Java boolfunc Main () {var i intfmt. Println (i, C, Python, Java)}