Created
September 20, 2022 13:47
-
-
Save wesleymatosdev/72cdc866f66bfd5351afa4a403bdfd30 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "fmt" | |
| func main() { | |
| s := []int{2, 3, 5, 7, 11, 13} | |
| printSlice(s) | |
| // Slice the slice to give it zero length. | |
| s = s[:0] | |
| printSlice(s) | |
| // Extend its length. | |
| s = s[:4] | |
| printSlice(s) | |
| // Drop its first two values. | |
| s = s[2:] | |
| printSlice(s) | |
| } | |
| func printSlice(s []int) { | |
| fmt.Printf("len=%d cap=%d %v\n", len(s), cap(s), s) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment