Two data types:
1. Language built-in data types
1) Numerical type:
① Integer type:
Unsigned: unit8, unit16, unit32, unit64
Signed: int8, int16, int32, int64
The following X represents the operating system of the X bit
unit = unitX, int = intX, unitptr = pointer to X
Type aliases:
byte = unit8
rune = int32
② Floating point :
float32 (single-precision floating point)
float64 (double precision floating point)
③ Imaginary number type (very novel) :
complex64
complex128
The above types can be used for + - * / operations , and integers can also be used for membrane operations.
2) String type:
string
C++ strings are made up of concatenated characters, while Golang is made up of bytes
With double quotes, the character " can be replaced by \ "
Basic operation:
Get string length: len(str)
E.g:
str string = "你"
fmt.Println(str[0])
The output is: 3 (because Golang strings are made of bytes)
Random access to a single character: str[i]
String concatenation: str1 + str2
3) Boolean:
bool
value is true , false
Unlike C ++ :
Any null value (nil) or zero value (0, 0.0, "") cannot be directly judged as a boolean
for example:
if 0 {
fmt.Println(" Error ")
}
It's wrong to write
2. Data types defined by self-defined data type methods provided by the language