This is a creation in Article, where the information may have evolved or changed.
Today say some basic knowledge of Golang, as well as your study will encounter problems, first explain Hello Word
[PHP]
Package Main
Import "FMT"
Func Main () {
Fmt. Println ("Hello, Micro Network");
}
[/php]
Package name packet mechanism, each independent go program needs to have a packaging main declaration, mainly for the bottom entry function main () to make a declaration, import and Java as imported package is below our function with the FMT. Println () This is a FMT package, Windows can install the win version of Go, Run command or the same, as long as go run *.go is running your go file can see the results, the main go build Hello.go will generate the execute file of the. exe.
Go language defines variables such as
[PHP]
var name type
var name1,name2,name3 type//multivariable
[/php]
Example program code example
[PHP]
var I string = "Hello, micro Network"//univariate
var d,u,h int = 1,2,4//define Multivariable
Func main () {
FMT. Println (d)
}
[/php]
Multivariable or multiple constants can be declared
[PHP]
package main;
Import "FMT"
Const (
N = +
str = "Hello, micro Network"
)
var (
m int
UI string
name float32
)
var i string = "Hello, micro network"
var d,u,h int = 1,2,4
Func main () {
FMT. Println (d)
}
[/php]
Go bit type: Rune, Int8, Int16, Int32, Int64 and Byte, Uint8, UInt16, UInt32, UInt64. Where Rune is Int32 's nickname, Byte is Uint8 's nickname.
Below is the note that the go language has a simple declaration and assignment C:=1 a:= ' Xiaowei ' These are automatically recognized types, but can no longer be defined in the function body
[PHP]
Package main;
Import "FMT"
var d,u,h int = 1,2,4
J:=3
Func Main () {
Fmt. Println (d)
}
The Non-declaration statement outside function body appears correctly as follows
Package main;
Import "FMT"
var d,u,h int = 1,2,4
Func Main () {
J:=3
Fmt. Println (d)
Fmt. Println (j)
}
[/php]
2. Declaration must be used or the error will be
[PHP]
var d,u,h int = 1,2,4
Func Main () {
J:=3
Fmt. Println (d)
}
The error that appears below 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)
}
[/php]
Today to get so many 1.1 points, his grammar and C Gray often similar, but also draw on a point Python interested can follow the study
Do not reprint any article of this station without permission:»golang basic knowledge of micro Network