notexOPENOverview
Notex/Languages/Measuring slice length
01.03LESSON 03 OF 33 · 1 MIN READ

Measuring slice length

Always free to read

Go provides several built-in functions to work with slices. You’ve already seen the built-in len function when looking at arrays. It works for slices too. Passing a nil slice to len returns 0.

Note

Functions like len are built into Go because they can do things that can’t be done by the functions that you can write. You’ve already seen that len’s parameter can be any type of array or any type of slice. You’ll soon see that it also works for strings and maps. In the Channels section, you’ll see it working with channels. Trying to pass a variable of any other type to len is a compile-time error. Go doesn’t let developers write a function that accepts any string, array, slice, channel, or map, but rejects other types.

Progress is saved on this device.
KEEP EXPLORING

One note leads to another.

Back to the library →
⌕
Search across the entire library ⌘ K