首页 > 其他 > 详细

go中三个点用法

时间:2019-06-01 23:36:35      阅读:85      评论:0      收藏:0      [点我收藏+]

go命令中三个点含义

An import path is a pattern if it includes one or more "..." wildcards, each of which can match any string, including the empty string and strings containing slashes. Such a pattern expands to all package directories found in the GOPATH trees with names matching the patterns. As a special case, x/... matches x as well as x‘s subdirectories. For example, net/... expands to net and packages in its subdirectories.

参考:https://blog.csdn.net/dongfengkuayue/article/details/52769322

 

golang中的三个点"…"的用法

‘…’ 其实是go的一种语法糖。 

它的第一个用法主要是用于函数有多个不定参数的情况,可以接收多个不确定数量的参数。  

第二个用法是slice可以被打散进行传递。

示例如下:

func test1(args ...string) {        //可以接受任意个string参数
    for _, v:= range args{
        fmt.Println(v)
    }
}

func main(){
var strss= []string{
        "qwr",
        "234",
        "yui",
        "cvbc",
    }
    test1(strss...)      //切片被打散传入
}

结果:

qwr
234
yui
cvbc

其中strss切片内部的元素数量可以是任意个,test1函数都能够接受。

第二个例子: 

var strss= []string{
        "qwr",
        "234",
        "yui",

}
var strss2= []string{
        "qqq",
        "aaa",
        "zzz",
        "zzz",
}
strss=append(strss,strss2...)      //strss2的元素被打散一个个append进strss
fmt.Println(strss)

结果:

[qwr 234 yui qqq aaa zzz zzz]

 

参考:https://blog.csdn.net/jeffrey11223/article/details/79166724

go中三个点用法

原文:https://www.cnblogs.com/embedded-linux/p/10961368.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!