slices

Contents

Roadmap info from roadmap website

Slices

Slices are similar to arrays but are more powerful and flexible. Like arrays, slices are also used to store multiple values of the same type in a single variable. However, unlike arrays, the length of a slice can grow and shrink as you see fit.

Array vs Slice

Slices:

  • Slices are similar to arrays, but are more powerful and flexible.
  • Like arrays, slices are also used to store multiple values of the same type in a single variable.
  • However, unlike arrays, the length of a slice can grow and shrink as you see fit.

Capacity vs length

  • len() function - returns the length of the slice (the number of elements in the slice)
  • cap() function - returns the capacity of the slice (the number of elements the slice can grow or shrink to)
#ready #online #reviewed #go #summary #informatic #data-structure #data-representation