This is a creation in Article, where the information may have evolved or changed.
Go is a statically typed language, and variables are of a definite type. The compiler checks the correctness of the variable type in the function call.
Use var
keywords to define variables.
The basic types of Go are:
bool
String
int int8 int16 int32 int64
UINT uint8 uint16 UInt32 UInt64 uintptr
BYTE//Uint8 Alias
Rune//Int32 aliases represent a Unicode code
float32 float64
Complex64 complex128
Look at the following example
Package Mainimport "FMT" Func Main () {//' var ' keyword is used to define one or more variables var a string = "initial" FMT. Println (a)//You can define multiple variables at once var b, c int = 1, 2 fmt. Println (b, c)//Go infers the type of the variable with the initial value var d = True FMT. When a variable is Println (d)//defined, a variable with no initial value is initialized by default to 0 value//integer 0 value is 0 var e int fmt. PRINTLN (E)//": =" syntax is a shortcut for defining and initializing variables f: = "short" FMT. Println (f)}
The output result is
Initial1 2true0short