The Go language has built-in functions that can be used without importing. They can sometimes operate on different types, such as len, cap, and append, or must be used for system-level operations, such as panic. Therefore, they need to be supported directly by the compiler.
The following is a simple list, and we will go into each of them in depth in the following chapters.
name descriptionclose | for pipe communication |
len、cap | len is used to return the length or quantity of a certain type (string, array, slice, map and pipe); cap is the meaning of capacity, used to return the maximum capacity of a certain type (only for slices and maps) |
new、make | Both new and make are used to allocate memory: new is used for value types and user-defined types such as custom structures, and make is used for built-in reference types (slices, maps, and pipes). They are used like functions, but with types as arguments: new(type), make(type). new(T) allocates a zero value of type T and returns its address, which is a pointer to type T (see Section 10.1 for details). It can also be used for primitive types: v := new(int) . make(T) returns the value after initialization of type T, so it does more work than new new() is a function, don't forget its parentheses |
copy、append | for duplicating and concatenating slices |
panic、recover | Both are used for error handling mechanisms |
print、println | The low-level printing function, it is recommended to use the fmt package in the deployment environment |
complex、real imag | for creating and manipulating complex numbers |