<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                我們已經知道切片創建的時候通常比相關數組小,例如: ~~~ slice1 := make([]type, start_length, capacity) ~~~ 其中?`start_length`?作為切片初始長度而?`capacity`?作為相關數組的長度。 這么做的好處是我們的切片在達到容量上限后可以擴容。改變切片長度的過程稱之為切片重組?**reslicing**,做法如下:`slice1 = slice1[0:end]`,其中 end 是新的末尾索引(即長度)。 將切片擴展 1 位可以這么做: ~~~ sl = sl[0:len(sl)+1] ~~~ 切片可以反復擴展直到占據整個相關數組。 示例 7.11?[reslicing.go](https://github.com/Unknwon/the-way-to-go_ZH_CN/blob/master/eBook/examples/chapter_7/reslicing.go) ~~~ package main import "fmt" func main() { slice1 := make([]int, 0, 10) // load the slice, cap(slice1) is 10: for i := 0; i < cap(slice1); i++ { slice1 = slice1[0:i+1] slice1[i] = i fmt.Printf("The length of slice is %d\n", len(slice1)) } // print the slice: for i := 0; i < len(slice1); i++ { fmt.Printf("Slice at %d is %d\n", i, slice1[i]) } } ~~~ 輸出結果: ~~~ The length of slice is 1 The length of slice is 2 The length of slice is 3 The length of slice is 4 The length of slice is 5 The length of slice is 6 The length of slice is 7 The length of slice is 8 The length of slice is 9 The length of slice is 10 Slice at 0 is 0 Slice at 1 is 1 Slice at 2 is 2 Slice at 3 is 3 Slice at 4 is 4 Slice at 5 is 5 Slice at 6 is 6 Slice at 7 is 7 Slice at 8 is 8 Slice at 9 is 9 ~~~ 另一個例子: ~~~ var ar = [10]int{0,1,2,3,4,5,6,7,8,9} var a = ar[5:7] // reference to subarray {5,6} - len(a) is 2 and cap(a) is 5 ~~~ 將 a 重新分片: ~~~ a = a[0:4] // ref of subarray {5,6,7,8} - len(a) is now 4 but cap(a) is still 5 ~~~ **問題 7.7** 1) 如果 a 是一個切片,那么?`s[n:n]`?的長度是多少? 2)?`s[n:n+1]`?的長度又是多少?
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看