This is a creation in Article, where the information may have evolved or changed.
Installation of 1.go languages
The blogger's environment is ubuntu14.04, so the installation of the Go language environment is directly used
sudo apt-get install Golang
After the installation is complete
2.hello World
The code is as follows
/* Hello.go */package Mainimport "FMT" Func Main () {FMT. Println ("hello,world!")}
Note Println Method P is uppercase
Then run the terminal compile
Go Run hello.go
or use the build command to build the executable file
Go Build
Some grammatical knowledge of 3.go
Go each individual statement does not require a special separator line, default to the line delimiter as the statement delimiter
Keyword var tag variable, const TAG constant
Declaration of a variable
package mainimport "FMT" Func main () { const ( a = 0 ; b ) const ( c = 0 ; d = 1 ) const e = 3 const f int8 The = 4 /* keyword iota represents a continuous, untyped integer constant, and iota defaults to 0 and increments incrementally. Each time the iota appears, its value is 0 */ const ( g = iota ; h ; i ) const j = iota var k int = 1 var l int l = 2 /* defaults to Int */ var ( m = 42949672960 ; n = 4294967296 ) var ( o int8 = 1 ; p = 1 ) fmt. Println (A) fmt. Println (b) fmt. Println (c) fmt. Println (d) fmt. Println (e) fmt. Println (f) fmt. Println (g) fmt. Println (h) fmt. Println (i) fmt. Println (j) fmt. Println (k) fmt. Println (L) fmt. Println (m) fmt. PRINTLN (n) fmt. Println (o) fmt. Println (P)}
The data type of GO is probably
boolean Types They are Boolean types, and it consists of two predefined constants: (a) True (b) False |
Numeric Types They are arithmetic types that represent integer types or B. The entire program floating-point value |
string Types: A String type represents a group string value. Its value is a sequence of bytes. The string is created at once by a stable type, which is not possible to change the contents of a string. The pre-declared string type is a string |
Derived types: They include: (a) pointer type, (b) array type, (c) struct type, (d) union type and (e) function type (f) slice class (g) function type (h) interface type (i) map type (j) Pipe type |
Boolean Types
BOOL type, variable value is only True,false
Assignment of 0, 1 is not supported
Package Mainimport "FMT" Func Main () {var a bool A = True FMT. Println (a) A = False fmt. Println (A)}
Output results
Numeric Types
Signed Integral type int8 int16 int32 int64
Unsigned integral type uint8 uint16 UInt32 UInt64
Floating point float32 float64
Retelling complex64 complex128
Other
byte identical to Uint8
Rune Identical to Int32
UINT 32-bit or 64-bit
int size is the same as uint
package mainimport "FMT" Func main () { fmt. Println (10/3) fmt. Println (10E5) fmt. Println (0x5) var a int8 a = 12 fmt. Println (a) var b int16 b = 12 fmt. Println (b) /* signed, so when C is greater than 127 or less than 127 it will error */ var c int8 c = 127 fmt. Println (c) /* unsigned, so when D is greater than 255 or less than 0 the error will be */ var d uint8 d = 255 fmt. Println (d) var e int e = 4294967297 fmt. Println (e) var f float32 f = 3.2 Fmt. Println (f) var g complex64 g = 3+2i fmt. Println (g)}
String Types
The smallest unit of the constituent string is the character, the smallest unit stored is the byte, and the string itself does not support modification.
Package Mainimport "FMT" Func Main () {/* default is int */var a = ' a ' var b = "abc" var c string = "abc" FMT. Println (a) fmt. Println (b) fmt. Println (c)}