Today, say some basic knowledge of Golang, as well as your study will encounter problems, first of all to explain Hello Word
Copy Code code as follows:
Package Main
Import "FMT"
Func Main () {
Fmt. Println ("Hello, cloud-dwelling community");
}
Package name package mechanism, each independent go program needs to have a package main statement, mainly for the bottom of the entry function main () to make a declaration, import and Java as imported package is the bottom of our function with the FMT. Println () This belongs to the FMT package, Windows can install the win version of Go, run the command or the same, as long as go run *.go is running your go file can see the results, the main went build Hello.go will generate the execute file of the. exe!
The go language defines variables as such
Copy Code code as follows:
var name type
var name1,name2,name3 type//multivariable
Example program code examples
Copy Code code as follows:
var i string = "Hello, cloud-dwelling community"//Single variable
var d,u,h int = 1,2,4//define Multivariable
Func Main () {
Fmt. Println (d)
}
Multivariable or multiple constants can be declared like this
Copy Code code as follows:
Package main;
Import "FMT"
Const
n = 100
str = "Hello, cloud-dwelling community"
)
var
m int
UI string
Name float32
)
var i string = "Hello, cloud-dwelling community"
var d,u,h int = 1,2,4
Func Main () {
Fmt. Println (d)
}
The types of Go digits: Rune, Int8, Int16, Int32, Int64 and Byte, Uint8, UInt16, UInt32, UInt64. Among them Rune is Int32 's nickname, Byte is Uint8 's nickname.
Below is note that the go language has simple declarations and assignments C:=1 a:= ' Xiaowei ' These are automatically recognized types, but cannot be defined in vitro
Copy Code code as follows:
Package main;
Import "FMT"
var d,u,h int = 1,2,4
J:=3
Func Main () {
Fmt. Println (d)
}
Appears non-declaration statement outside function body correct is as follows
Package main;
Import "FMT"
var d,u,h int = 1,2,4
Func Main () {
J:=3
Fmt. Println (d)
Fmt. Println (j)
}
2. Declared must use otherwise will be an error
Copy Code code as follows:
var d,u,h int = 1,2,4
Func Main () {
J:=3
Fmt. Println (d)
}
There is an error on the bottom of J declared and not used correct is
var d,u,h int = 1,2,4
Func Main () {
J:=3
Fmt. Println (d)
Fmt. Println (j)
}
Today to get so many 1.1 points, his grammar and C Gray is often similar, but also learn from the point Python interested can follow