码迷,mamicode.com
首页 > 编程语言 > 详细

Go语言集合

时间:2019-09-20 20:45:04      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:判断   col   pre   中括号   大小   int   array   var   for   

ZERO.  数组

1.  创建 一个不固定大小的数组

  var array [] int

2.  遍历

var nums1 = []int {1,6,7}

for _, n := range nums1{
        fmt.Println(n)    //输出结果为1,6,7
}
for i, n:= range nums1{
  fmt.Println(n)    
//输出结果为1,6,7
  fmt.Println(i)    //输出结果为0,1,2
}

 

一.  Map

1.  创建map

  var m = make(map[int]int)  //第一个int为key,第二个int不加中括号为val

2.  添加

  m[2] = 1  //添加key为2,val为1

3.  判断是否存在

  _, ok := m[3]  //判断3这个key是否存在 ,存在ok就是true,不存在ok就是false

  if ok{

  }  

 

Go语言集合

标签:判断   col   pre   中括号   大小   int   array   var   for   

原文地址:https://www.cnblogs.com/da-peng/p/11559429.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!