1 built-in functions
The Len () function can accept different type parameters and return the length of that type .
If we pass in a string, the length of the string is returned ,
If an array is passed in, the number of elements contained in the array is returned.
2 Custom Functions
// function returns a single value func Max (A, b int ) int { if a > b { return A} else { return b }} // function returns multiple values func Swap (A, B int ) (int , int ) { return B, a}
3 value passing and reference passing
var int 1 Ten Swap2 (&aa, &BB) FMT. PRINTLN (AA) *int, b *int) () { varint = *a *a = *b *b = Temp}
4 function methods
A method is a function that contains the recipient, which can be either a value of a named type or struct type or a pointer. All methods of the given type belong to the method set of that type
Package Main
Import "FMT"
Type Circle struct { //define struct body
Radius float64
}
Func Main () {
var c Circle
C.radius = 10.00
Fmt. Println ("area of the C is", C.getarea ()) //method that can directly invoke the struct body
}
Func (c Circle) Getarea () float64 { //This method is a struct-body method
Return 3.14*c.radius*c.radius
}
5 function closures
Tenth lesson Go language function