标签:%s ring col package int nbsp color 容器 lis
1 //一个参数的函数 2 package main 3 4 import "fmt" 5 6 func main() { 7 haha("小明") 8 } 9 func haha(name string) { 10 fmt.Printf("你好,%s\n", name) 11 }
1 package main 2 3 import "fmt" 4 5 func main() { 6 haha("小明", 10) 7 } 8 func haha(name string, n int) { 9 for i := 0; i < n; i++ { 10 fmt.Printf("你好,%s\n", name) 11 12 } 13 }
1 //类型: 切片容器 类似python 的list 2 3 package main 4 5 import "fmt" 6 7 func main() { 8 haha("小明", "小红", "小芳") 9 } 10 11 func haha(names ...string) { 12 for i, name := range names { 13 fmt.Printf("你好No.%d: %s\n ", i, name) 14 } 15 }
1 package main 2 3 import "fmt" 4 5 func main() { 6 haha("小明", "小红") 7 } 8 //类型合并 9 func haha(name1, name2 string) { 10 11 fmt.Printf("你好 %s\n ", name1, name2) 12 13 }
标签:%s ring col package int nbsp color 容器 lis
原文地址:https://www.cnblogs.com/chaoyangxu/p/11799243.html