Golang Basic Knowledge

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.