A, why learn the go language?
From a personal point of view, the first is by the go language legend of the ultra-high development efficiency and efficiency of the attraction; the second is that the go language supports concurrency at the language level, which is very convenient in today's programming business; The third is because the first two points, I think in the future go will fire up; Follow Microsoft or Google will always have meat to eat ^_^!
B, the first GO program
According to international practice, learn a language, always start with a Hello world, again, see the first go program to feel the Go
Package Mainimport "FMT" Func Main () { fmt. Println ("Hello world!")}
Package---Packet declaration that indicates which package this code belongs to
Import---Importing a package, importing FMT because you need to use the println function in the FMT package//cannot import packages that are not used in the code, compile will error
/****************** Start Language *********************/
First, sequential programming
1. Variables
A, statement:
Introducing the keyword VAR, type information after the variable name
var a int
var v2 string
var v3 [ten]int //array
/* Multiple variables declared together */
VAR (
v1 int
V2 string
)
B, initialization
var v1 int = 10var v2 = 10//can automatically deduce type v3: =//v3 cannot be a variable that has already been declared
C, assigned value
var v4 INTV4 = 10
/* Multiple assignments */
A, B = 2, 3
I, j = j, I
D, anonymous variables
The go language supports multiple return values and anonymous variables, because functions can return multiple values, and can be selectively received when received
Func getName (FirstName, LastName, nickname) { return "Zhangsan", "Lisi", "Wuhaha"}_, _, Nickname: = GetName ()
2. Constants
A, literal constants-----hard-coded constants in the program (no type)
-12 3.14159265358979325846//floating-point constant 3.2 + 12i//plural constant true//Boolean constant "foo"//String type constant
b, constant definition
Keyword const
Const Pi float64 = 3.14159265358979323846const (Size int64 = 1024x768 EOF =-1) Const MASK = 1 << 3//constant expression for compile-time operation
Constant assignment is a compile-time behavior, so the right value cannot be any expression that requires a run-time to produce a result
The following errors are chestnuts:
Const Errooooor = os. GETENV ("HOME")//os. GETENV () to produce results at run time
C, pre-defined constants
True, False, iota
Iota---Constants that can be modified by the compiler, appear once per const, iota reset to 0, and do not appear the number represented by the Iota,iota once before the next const appears +1
Const ( C0 = Iota//co = = 0 C1 = Iota//c1 = = 1 C2 = Iota//c2 = = 2 ) const ( C0 = 1 << Iota//c0 = = 1 c1 = 1 << Iota//c1 = 2 c2 = 1 << Iota//c2 = = 4 )
D, enumeration---Define a set of constants
Const (
Sunday = Iota
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Numberofdays//This constant is not exported
)
As with other symbols in the go language, constants that begin with a capital letter are visible outside the package . In the example above , Numberofdays is private in the package and other symbols can be accessed by other packages .
"Go" Go language learning note one