Get Length in Go

Posted by yhuang
Public (Editable by Users)
Go
Edit
package main

import (
	"fmt"
)

func main() {

	var a []int

	// In Go, the length of a nil slice is 0
	fmt.Println(len(a))

	a = append(a, 1, 2, 3)
	fmt.Println(len(a))
}