Slices, maps and strings

Lists with arrays and slices, key and value pairs with maps, and text with strings and runes.

About 4 hours of study

Learning objectives

Lessons

  1. 1

    Arrays and slices

    Fixed-size arrays, growable slices, append, len, make, slicing with a[low:high], range, copy, sorting with sort.Ints and slices of slices.

  2. 2

    Maps

    Storing key and value pairs with maps: creating, adding, reading with the comma ok form, deleting, counting, maps of slices, and printing in a fixed order by sorting the keys.

  3. 3

    Strings, runes and the strings package

    How Go stores text as bytes, the difference between bytes and runes, indexing and slicing strings, looping with range, and the useful functions of the strings package.

Module practice

Module quiz

1. What does append return?
2. Which line reads a map value and tells whether the key exists?
3. What is the index of the first item of a slice?
4. What is len("héllo") in Go?
5. In which order does range visit a map?
6. What happens when you change an item of the part nums[1:3]?

‹ Control flow and functionsStructs, methods and interfaces ›