首页 > 编程语言 > 详细

Go语言学习笔记(2)

时间:2018-08-15 23:34:10      阅读:167      评论:0      收藏:0      [点我收藏+]

数组

var a [2]string
a[0] = "Hello"
a[1] = "World"
primes := [6]int{2, 3, 5, 7, 11, 13}
// 切片(半开区间)
var s []int = primes[1:4]
names := [4]string{
    "John",
    "Paul",
    "George",
    "Ringo",
}
a := names[0:2] // [John Paul]
b := names[1:3] // [Paul George]
b[0] = "XXX" // a == [John XXX]  b == [XXX George]
// 切片字面量
q := []int{2, 3, 5, 7, 11, 13}
r := []bool{true, false, true, true, false, true}
s := []struct {
    i int
    b bool
}{
    {2, true},
    {3, false},
    {5, true},
    {7, true},
    {11, false},
    {13, true},
}
//
s := []int{2, 3, 5, 7, 11, 13}
s = s[1:4] // [3 5 7]
s = s[:2] // [3 5]
s = s[1:] // [5]

Go语言学习笔记(2)

原文:https://www.cnblogs.com/zwvista/p/9484645.html

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