Created
October 27, 2015 23:57
-
-
Save mayra-cabrera/43e9544f0de45363b0fb to your computer and use it in GitHub Desktop.
This file contains 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() { | |
orgSlice := make([]string, 5, 8) | |
orgSlice[0] = "Apple" | |
orgSlice[1] = "Orange" | |
orgSlice[2] = "Banana" | |
orgSlice[3] = "Grape" | |
orgSlice[4] = "Plum" | |
orgSlice2 := orgSlice[2:4] | |
fmt.Println(orgSlice2) | |
fmt.Printf("%s: %d\n", "Cap", cap(orgSlice2)) | |
fmt.Printf("%s: %d\n", "Len", cap(orgSlice2)) | |
for _, v := range orgSlice2 { | |
fmt.Println("-" + v) | |
} | |
orgSlice3 := orgSlice2[1:cap(orgSlice2)] | |
fmt.Println(orgSlice3) | |
fmt.Printf("%s: %d\n", "Cap", cap(orgSlice3)) | |
fmt.Printf("%s: %d\n", "Len", cap(orgSlice3)) | |
for _, v := range orgSlice3 { | |
fmt.Println("-" + v) | |
} | |
orgSlice[3] = "hola" | |
fmt.Println("orgSlice: " + orgSlice[3]) | |
fmt.Println("orgSlice: " + orgSlice2[1]) | |
fmt.Println("orgSlice: " + orgSlice3[0]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment