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 ...

Get Get Programming with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.