64_Go基础_1_31 函数的类型
1 package main 2 3 import "fmt" 4 5 func fun1() {} 6 7 func fun2(a int) int { 8 return 0 9 } 10 11 func fun3(a float64, b, c int) (int, int) { 12 return 0, 0 13 } 14 15 func fun4(a, b string, c, d int) (string, int, float64) { 16 return "", 0, 0 17 } 18 19 func main() { 20 /* 21 go语言的数据类型: 22 基本数据类型: 23 int,float,bool,string 24 25 复合数据类型: 26 array,slice,map,function,pointer,struct,interface。。。 27 28 29 函数的类型: 30 func(参数列表的数据类型)(返回值列表的数据类型) 31 32 */ 33 34 a := 10 35 fmt.Printf("%T\n", a) // int 36 b := [4]int{1, 2, 3, 4} 37 fmt.Printf("%T\n", b) // [4]int 38 39 /* 40 [4]string 41 [6]float64 42 */ 43 44 c := []int{1, 2, 3, 4} 45 fmt.Printf("%T\n", c) // []int 46 47 d := make(map[int]string) 48 fmt.Printf("%T\n", d) 49 50 /* 51 map[string]string 52 map[string]map[int]string 53 */ 54 55 fmt.Printf("%T\n", fun1) // func() 56 fmt.Printf("%T\n", fun2) // func(int) int 57 fmt.Printf("%T\n", fun3) // func(float64, int, int) (int, int) 58 fmt.Printf("%T\n", fun4) // func(string,string,int,int)(string,int ,float64) 59 }