var and const: Declarations of variables and constants
var varName type or VarName: = value
Package and import: Importing
Func: Used to define functions and methods
Return: For returning from a function
Defer Somecode: Executes before the function exits
Go: for Parallel
Select for different types of communication
Interface for defining interfaces
struct is used to define abstract data types
Break, case, continue, for, Fallthrough, else, if, switch,
Goto, default Process Control
Chan for Channel Communications
Type is used to declare a custom type
Map for declaring map type data
Range for reading slice, map, channel data
Uppercase, which is public
Constants are determined at compile time and cannot be changed at runtime.
The go language also allows the keyword "var" to be omitted when declaring variables. and replace it with ":"
。 eg:count:=10
Data beyond the range of values will overflow. such as Var a int8=127 fmt. Println (A
+1)//This time output-128
The general number of digits is more used to store float64.
BYTE type and uint8 essence are the same, just an alias, easy to read the program. Also to
Note that the character output is to be converted first, and the byte-type data is output directly to the shaping
Eg:var I,j Byte
i=65//to String (i) output a
j= ' A '//Direct output is 65
The essence of Rune and Int32 is the same, alias, easy to read. Rune is a Unicode encoding
The default value of the pointer variable after initialization is nil is not null,go in null
<< is a bitwise operator, and if no overflow occurs, <<1 is equal to 2 times the one-time side, moving left 10
The equivalent is multiplied by 2 of the 10-time square.
The &^ is a flag-bit cleanup operator, such as binary for the binary of a 00000110,b as
00001011, then a&^b=00000100, the principle is based on the position of 1 on the B, if the same
Position A is 0, then unchanged, if 1 is changed to 0,b is 5 7 8 bits for 1,a on 5 bits 0,
Unchanged, 7 bits is 1, becomes 0, 8 bits is 0, does not change, so the result is 00000100
Go language operation from left to right when priority is the same
Go string traversal is divided into byte-count traversal and Unicode traversal
BYTE traversal is like for the simplest use, the following mainly looks at Unicode traversal:
Eg:str:= "AAAA was good"
For i, ch: = Range str {
Fmt. Printf ("str[%d]=%v\n", I, CH)
The}/* output is:
str[0]=97
str[1]=97
str[2]=97
str[3]=97
str[4]=30495
str[7]=22909*/
Initialization of a constant group
const{
a=100
B
C
}
Func Main () {
Fmt. Println (a)
Fmt. Println (b)
Fmt. Println (c)
}//output is three x 100;
The principle is that if you do not provide an initial value, the use of an upstream expression is indicated.
However, this method is only tried in a constant group.
Enumeration:
Similar to constant group definitions, different places in the back add =iota//starting from 0
An example:
Const
_=iota//ignoring the situation where iota is 0
KB float64=1<< (10*iota)
MB
GB
TB
)
Func Main () {
Fmt. Println (KB)
Fmt. Println (MB)
Fmt. Println (GB)
Fmt. Println (TB)
}//will show 1024 1048576 1073741824 1099511627776 means that all units are multi-
Less byte
The initial value of bool is false
The initial values for both complex62 and complex128 are 0+0i.
Global variables trial var
Local variables can omit Var
Because the go language is a type-safe language, all type conversions are explicit
Int--float (float cast to int reserved integer part)
String--[]byte
String--[]int
The end of chapter two is basically enough basic data types and defining constant variables. Need special
Don't pay attention to iota and explicit conversions!
The third chapter will continue to make unremitting efforts!
Go Language Summary Chapter II