O'Reilly logo

Get Programming with Go by Nathan Youngman and Roger Peppé

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Lesson 17. Slices: windows into arrays

After reading lesson 17, you’ll be able to

  • Use slices to view the solar system through a window
  • Alphabetize slices with the standard library

The planets in our solar system are classified as terrestrial, gas giants, and ice giants, as shown in figure 17.1. You can focus on the terrestrial ones by slicing the first four elements of the planets array with planets[0:4]. Slicing doesn’t alter the planets array. It just creates a window or view into the array. This view is a type called a slice.

Figure 17.1. Slicing the solar system

Consider this

If you have a collection, is it organized in ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required