切片的长度、容量

 1 package main
 2 
 3 import "fmt"
 4 
 5 func main() {
 6     a := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
 7     s1 := a[:]
 8     fmt.Println("s1=", s1)
 9     fmt.Printf("len=%d, cap=%d\n", len(s1), cap(s1))
10 
11     s2 := a[3:6:7]
12     fmt.Println("s2=", s2)
13     fmt.Printf("len=%d, cap=%d\n", len(s2), cap(s2))
14 
15     s3 := a[:6]
16     fmt.Println("s3=", s3)
17     fmt.Printf("len=%d, cap=%d\n", len(s3), cap(s3))
18 
19     s4 := a[3:]
20     fmt.Println("s4=", s4)
21     fmt.Printf("len=%d, cap=%d\n", len(s4), cap(s4))
22 }
View Code

相关文章:

  • 2022-12-23
  • 2021-10-29
  • 2021-07-22
  • 2021-06-22
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
猜你喜欢
  • 2022-02-06
  • 2021-06-24
  • 2021-10-13
  • 2021-07-07
  • 2021-11-20
相关资源
相似解决方案