This is a creation in Article, where the information may have evolved or changed.
Boolean type
The value of the Boolean type in Go has true and false two, defined by the BOOL keyword
Number Type
The type defined by int is determined by the number of bits in go, for example, on a 32 system, int is 32 bits and 64 bits on a 64-bit system. If you want to define an int data with a different number of digits, you need to specify explicitly, such as Int8,int16,int32. There are two separate aliases in go: Rune and Byte,byte are aliases for Uint8, Rune is the alias of Int32, Rune is used primarily to traverse characters in a string (UTF-8 encoding)
Constant
Go uses the keyword const to define constants, the type of the constant can only be, a numeric type, a string, a bool type, the definition of the form may be as follows:
Const A=10
Enum type
Define it with key iota.
Const
A=iota
B=iota
Where a=0,b=1, the timing can be canceled when the repetition of the Iota key:
Const
int A=iota
int b
The enumeration type can also specify the type of the variable:
Const (
A = 0
b string = "0"
After that, a is shaping, and B is the string type.
String type
Use string to define the string type var a string= "Aagagag" can also be rewritten as: a: = "aagagag", they are equivalent.
In Go, the string type will not be able to be modified like the C language:
For example: String str= "Qwertyu" in C language;
str[0]= ' d '; this is legal in the C language, but it's illegal in go
If you want to modify the value of a string in go, you need to use the following method:
s: = "Hello"
c: = []byte (s)
C[0] = ' C '
S2: = string (c)
Fmt. Printf ("%s\n", S2)
A very important point of the string in Go is a multi-line string: A multiline string can be defined with a + or ' definition '.
Define with +:
S: = "Starting part" +
"Ending part"
Define with single quotation marks
S: = ' starting part
Ending part '
After the appeal method is determined, the value of S is inclusive of line breaks and spaces.
Plural
The Go language native is supports the plural, its key word is complex128 (the imaginary part divides into 64 bits), the complex64 (the imaginary part divides into 32 bits), the definition method is as follows:
var comp complex64=23+43i