企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
### 概述 不定长参数只能放在最后面,固定参数一定要传参,不定参数可以不传参 . ~~~ func main() { show(10,20,30,40,50) } func show(a ,b int,args ...int){ fmt.Print(a,b,args) } ~~~ ~~~ 10 20 [30 40 50] ~~~ ### 将不定长参数传递给其他函数 可以使用args... 将不定长的参数进行传递 ~~~ func main() { show(10, 20, 30, 40, 50) } func show(args ...int) { show1(args...) //show1(args[2:]...) 传递后三个参数 } func show1(temp ...int) { for _, data := range temp { fmt.Printf("%d---", data) } } ~~~ ~~~ 10---20---30---40---50--- ~~~