在官方文档中,经常出现以下代码。
func Printf(format string, a ...interface{}) (n int, err error)
什么是a
和...
分别是什么意思?
a
是一个变量,就像其他变量一样。...
是一种将很多论点切成薄片的方法。
它可以写成:
func Printf(format string, a []interface{}) (n int, err error)
但是您必须这样称呼它:
Printf("", []interface{1,2,3})
而不是像这样
Printf("", 1, 2, 3)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句