Go language (Golang) Basics _golang

Source: Internet
Author: User

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

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.