Built-in function

Go len()

Reports byte length for strings, element count for arrays and slices, key count for maps, and queued element count for channels. Array pointers are also accepted. Nil slices, maps and channels have length zero. Example prints 2 for one UTF-8 rune.

Formal Syntax & Structure

go syntaxgo
len(v)

Parameters & Attributes

NameTypeDescription
vstring, array, array pointer, slice, map or channelValue whose length is queried.

Return Value

int

Length, sometimes a constant.

Working Example

Example Snippetgo
package main
import "fmt"
func main() {  fmt.Println(len("é"))}
Go Reference