Newer
Older
01_hello / collection / slice.go
yhornisse on 24 Sep 2021 560 bytes rename dir
package main

import "fmt"

func main() {
	s := []string{0:"", 1:"Jan", 2:"Feb", 3:"Mar", 4:"Apr", 5:"May", 6:"Jun", 7:"Jul", 8:"Aug", 9:"Sep", 10:"Oct", 11:"Nov", 12:"Dec"}
	fmt.Printf("%d\n", len(s)) // 13(0-12)
	fmt.Printf("%+v\n", s[2:4]) // [Feb Mar]
	fmt.Printf("%d\n", len(s[2:4])) // 2
	fmt.Printf("%d\n", cap(s[2:4])) // 11(2-12)
	fmt.Printf("%+v\n", s[2:7]) // [Feb Mar Apr May Jun]
	fmt.Printf("%d\n", len(s[2:7])) // 5
	fmt.Printf("%d\n", cap(s[2:7])) // 11(2-12)
	fmt.Printf("%+v\n", s[:]) // [ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec]
}