Built-in Functions
A few functions are predefined, meaning you don’t have to include any packageto get access to them. lists them all.6
close | new | panic | complex |
delete | make | recover | real |
len | append | print | imag |
cap | copy | println |
Pre-defined functions in Go.
These built-in functions are documented in the builtin
pseudo package that is included in recent Go releases. Let’s go over thesefunctions briefly.
close
- is used in channel communication. It closes a channel. We’ll learn more about this in .
delete
- is used for deleting entries in maps.
len
andcap
- are used on a number of different types,
len
isused to return the lengths of strings, maps, slices, andarrays. In the next section we’ll look at slices,arrays and the functioncap
. new
- is used for allocating memory for user defineddata types. See .
make
- is used for allocating memory for built-intypes (maps, slices, and channels). See .
copy
,append
copy
is for copying slices. Andappend
is for concatenating slices. See in this chapter.panic
,recover
- are used for an exception mechanism. See for more.
print
,println
- are low level printing functions that can be used without reverting to the
fmt
package. These are mainly used for debugging.built-in,println) complex
,real
,imag
- all deal with complex numbers. We will not use complex numbers in this book.
当前内容版权归 Miek Gieben 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 Miek Gieben .