Simple slices example
This commit is contained in:
commit
c959795558
21
slices/go.go
Normal file
21
slices/go.go
Normal file
@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
p := []int{2, 3, 5, 7, 11, 13}
|
||||
fmt.Println("p ==", p)
|
||||
|
||||
for i := 0; i < len(p); i++ {
|
||||
fmt.Printf("p[%d] == %d\n", i, p[i])
|
||||
}
|
||||
|
||||
// slice index notation: (python)
|
||||
fmt.Println("p[1:4] == ", p[1:4])
|
||||
fmt.Println("p[:3] == ", p[:3])
|
||||
fmt.Println("p[4:] == ", p[4:])
|
||||
|
||||
v := make([]string, 0)
|
||||
v = append(v, "hello", "world")
|
||||
fmt.Printf("%v\n", v)
|
||||
}
|
Loading…
Reference in New Issue
Block a user