定义函数,小括号里面是参数
func saylovetosb (name string,num int){ for i := 1; i <= num; i++ { fmt.Printf("我爱%s\n",name) }}func main() { saylovetosb("拉芳",10)}
不定长参数 必须要放在参数的末尾
func saylovetosb2(names ...string) { fmt.Printf("我爱%s\n",names)}func main() { saylovetosb2("拉芳","拉草","拉潘婷")}
执行结果
多个参数,类型相同可以合并
//func saylovetosb2(name string,name2 string,num int) { 可以合并为下面的写法func saylovetosb2(name ,name2 string,num int) { fmt.Printf("我爱%s\n",)}func main() { saylovetosb2("拉芳","拉草","拉潘婷")}