1
0
gotour-notes/slices/go.go

30 lines
556 B
Go
Raw Normal View History

2012-08-01 08:11:34 -07:00
package main
import "fmt"
import "sort"
2012-08-01 08:11:34 -07:00
func main() {
p := []int{2, 3, 13, 7, 5, 11}
fmt.Println("p ==", p)
sort.Ints(p)
fmt.Printf("%T p: %v\n", p, p)
2012-08-01 08:11:34 -07:00
for i := 0; i < len(p); i++ {
fmt.Printf("p[%d] == %d\n", i, p[i])
}
2012-08-01 08:11:34 -07:00
// 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, 30, 1024)
fmt.Printf("%v\n", v)
fmt.Printf("%v\n", cap(v))
v = append(v, "hello", "world")
fmt.Printf("%v\n", v)
2012-08-01 08:11:34 -07:00
:= 12.34
fmt.Printf("%v\n", )
2012-08-01 08:11:34 -07:00
}