<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ## 一、定義切片 ~~~ package main import "fmt" func main() { // 切片和數組不同的是,數組是指定長度的,切片是不指定長度的 // 空切片 var s1 []int fmt.Println(s1) s2 := []int{} fmt.Println(s2) // 使用make來申明切片 // 這里的0,0表示的是長度和容量都是0 var s3 =make([]int,0,0) fmt.Println(s3) s4 := []int{1,2,3,4} fmt.Println(s4) } ~~~ ## 二、操作切片 append():向切片尾部添加數據 copy() #### 實例1 ~~~ package main import "fmt" func main() { // 向空切片添加元素 var s1 []int s1 = append(s1,0) s1 = append(s1,1,2,3) s1 = append(s1,4) s1 = append(s1,5,6,7,8,9) fmt.Println(s1) //創建指定大小的切片 s2 := make([]int,5) s2 = append(s2,6) fmt.Println(s2) // 創建并初始化切片 s3 := []int{1,2,3} s3 = append(s3,4,5,6) fmt.Println(s3) } ~~~ 運行結果為: [0 1 2 3 4 5 6 7 8 9] [0 0 0 0 0 6] [1 2 3 4 5 6] ## 三、實例 #### 實例1 ~~~ package main import "fmt" func main() { // 定義一個數組 arr := [...]int{1,2,3,4,5,6,7,8,9} //取切片 //這里的賦值可以理解為對原數組的一個映射,并沒有創建和copy出來一個新的切片 s1 :=arr[2:] //修改值 s1[0] = 100 fmt.Println(s1) fmt.Println(arr) } ~~~ 結果: [100 4 5 6 7 8 9] [1 2 100 4 5 6 7 8 9] #### 實例2 ~~~ package main import "fmt" func main() { // 定義一個數組 arr := [...]int{1,2,3,4,5,6,7,8,9} //取切片 //這里的賦值可以理解為對原數組的一個映射,并沒有創建和copy出來一個新的切片 s1 :=arr[2:] //修改值 s1[0] = 100 //fmt.Println(s1) //fmt.Println(arr) s2 := arr[2:6] fmt.Println(s2) // go語言沒有取到的位置,可以向后延伸,不可向前延伸 s3 := s2[3:5] fmt.Println(s3) } ~~~ 運行結果: [100 4 5 6] [6 7]
                  <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>

                              哎呀哎呀视频在线观看