zoukankan      html  css  js  c++  java
  • A Tour of Go Slicing slices

    ---恢复内容开始---

    Slices can be re-sliced, creating a new slice value that points to the same array.

    The expression

    s[lo:hi]

    evaluates to a slice of the elements from lo through hi-1, inclusive. Thus

    s[lo:lo]

    is empty and

    s[lo:lo+1]

    has one element.

    package main 
    
    import "fmt"
    
    func main() {
        p := []int{2, 3, 5, 7, 11, 13}
        fmt.Println("p ==", p)
        fmt.Println("p[1:4] ==", p[1:4])
    
        //missing low index implies 0
        fmt.Println("p[:3] ==", p[:3])
    
        // missing high index implies len(s)
        fmt.Println("p[4:] ==", p[4:])
    }
    package main 
    
    import "fmt"
    
    func main() {
        p := []int{2, 3, 5, 7, 11, 13}
        fmt.Println("p ==", p)
        fmt.Println("p[1:4] ==", p[1:4])
    
        //missing low index implies 0
        fmt.Println("p[:3] ==", p[:3])
    
        // missing high index implies len(s)
        fmt.Println("p[4:] ==", p[4:])
        var a [2]string
        a[0] = "Hello"
        a[1] = "World"
        fmt.Println(a[0:1])
    }
  • 相关阅读:
    黑色边影,
    拉伸的代码,
    一定是selection的原因啊,要不然呢,
    status bar的差别,
    黄色,
    域名错了,
    node=day4
    PS切片
    移动端插件IScroll.js
    移动web资源概论
  • 原文地址:https://www.cnblogs.com/ghgyj/p/4053317.html
Copyright © 2011-2022 走看看