This is a creation in Article, where the information may have evolved or changed.
Preface: In the Go programming language, data types are used to declare functions and variables. Data types appear to be in order to divide the data into the required memory size of the data, programming when you need to use big data when you need to apply for large memory, you can make full use of memory.
First, the number type
Signed integers are represented by a 2 complement, which means that the highest bit is used to represent the sign bit, and a n-bit of the signed number ranges from -2^{n-1}−2n−1 to 2^{n-1}-12n−1−1. All bit bits of an unsigned integer are used to represent non-negative numbers, and the range is 0 to 2^n-12n−1. For example, the range of int8 type integers is from 128 to 127, while the value of uint8 type integers ranges from 0 to 255.
1.1 Integral type
Serial Number |
Type and Description |
1 |
uint8: unsigned 8-bit integer (0 to 255) |
2 |
uint16: unsigned 16-bit integer (0 to 65535) |
3 |
UInt32: unsigned 32-bit integer (0 to 4294967295) |
4 |
UInt64: unsigned 64-bit integer (0 to 18446744073709551615) |
5 |
int8: signed 8-bit integer (-128 to 127) |
6 |
Int16: signed 16-bit integer (-32768 to 32767) |
7 |
int32: signed 32-bit integer (-2147483648 to 2147483647) |
8 |
Int64: signed 64-bit integer (-9223372036854775808 to 9223372036854775807) |
1.2 Floating-point type
The go language provides two precision floating-point numbers, float32 and float64. Their arithmetic specifications are defined by the IEEE754 floating point International standard, and the floating-point specification is supported by all modern CPUs.
Serial Number |
Type and Description |
1 |
float32: IEEE-754 32-bit floating-point number |
2 |
float64: IEEE-754 64-bit floating-point number |
3 |
complex64: 32-bit real and imaginary numbers |
4 |
complex128: 64-bit real and imaginary numbers |
Demo Example:
package mainimport ("math""fmt")func main() {maxuint := uint64(math.MaxUint64)fmt.Println("maxuint is :",maxuint)fmt.Printf("maxfloat32 is :%v\n",math.MaxFloat32)fmt.Printf("maxfloat64 is :%v\n",math.MaxFloat64)}运行结果:maxuint is : 18446744073709551615maxfloat32 is :3.4028234663852886e+38maxfloat64 is :1.7976931348623157e+308
1.3 Other number types
Serial Number |
Type and Description |
1 |
byte: type alias of Uint8 |
2 |
Rune: type Aliases for Int32 |
3 |
UINT: 32 or 64 bits |
4 |
int: 32 or 64 bits |
5 |
uintptr: unsigned integer for holding a pointer |
Two, Boolean type
There are only two values for a Boolean type: True and false. The conditional portions of the IF and for statements are boolean-type values, and the comparison operations such as = = and < also produce Boolean values.
Three, string
A string is a value type, and the value is immutable, that is, you cannot modify the contents of the text again after you create it, and in more depth, the string is a fixed-length array of bytes.
Go supports the following 2 forms of literals:
Explanation String: The class string is enclosed in double quotation marks, where the associated escape character is replaced
\a 响铃\b 退格\f 换页\n 换行\r 回车\t 制表符\v 垂直制表符\' 单引号 (只用在 '\'' 形式的rune符号面值中)\" 双引号 (只用在 "..." 形式的字符串面值中)\\ 反斜杠
Non-explanatory string: The class string is enclosed in inverted quotation marks.
`This is a raw string \n` 中的 `\n` 会被原样输出
In order to facilitate communication, I opened the public number (attention to see more wonderful) and QQ Group, QQ Group 1 (291519319) and QQ Group 2 (659336691). Like the technology to communicate with it