Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import "fmt"
- func main() {
- a := []int{2, 3, 5, 7, 11, 13}
- printSlice(a)
- // Slice the slice to give it zero length.
- s := a[:0]
- printSlice(s)
- // Extend its length.
- s = a[1:4]
- printSlice(s)
- // Extend its length.
- s = s[0:5]
- printSlice(s)
- // Drop its first two values.
- s = a[2:]
- printSlice(s)
- s = append(s, 35)
- printSlice(s)
- printSlice(a)
- }
- func printSlice(s []int) {
- fmt.Printf("len=%d cap=%d %v\n", len(s), cap(s), s)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement