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() { | |
| hello := []string{"h", "e", "l", "l", "o"} | |
| world := []string{"w", "o", "r", "l", "d"} | |
| fullHello := hello[:] | |
| fmt.Println(fullHello) |
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
| a[0:10] | |
| a[:10] | |
| a[0:] | |
| a[:] |
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
| var a [10]string |
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
| []string{"h", "e", "l", "l", "o"} |
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() { | |
| names := [4]string{ | |
| "John", | |
| "Paul", | |
| "George", | |
| "Ringo", |
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
| // _Slices_ are a key data type in Go, giving a more | |
| // powerful interface to sequences than arrays. | |
| package main | |
| import "fmt" | |
| func main() { | |
| // Unlike arrays, slices are typed only by the |
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
| c := make([]string, len(s)) | |
| copy(c, s) | |
| fmt.Println("copy: ", c) |
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
| s := make([]int, 0) | |
| s = append(s, "h", "e", "l", "l", "o") | |
| s = append(s, " ") | |
| s = append(s, "w", "o", "r", "l" "d") | |
| fmt.Println("append: " s) |
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
| s := make([]int, 5) |
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() { | |
| var a [2]string | |
| a[0] = "Hello" | |
| a[1] = "World" | |
| fmt.Println(a[0], a[1]) | |
| fmt.Println(a) |