Slices and Maps
Part of the Go course
Every variable you have used so far holds exactly one value: one name, one age, one price. Most real problems involve a group of things: a roster of students, a shopping cart, a lookup table of prices by item name. Go gives you two built-in collection types for exactly this, and you will reach for one of them in almost every program you write from here on.
Picture a slice as a row of labeled boxes on a shelf, numbered starting from 0, each box holding one value of the same type as all the others. You create one with a slice literal, listing the values inside braces:
Want to learn Go Slices and Maps in a real environment?
Click below, get a fresh Linux box with Go ready to go, and work through Slices and Maps hands-on with an AI tutor that knows your code.
Start this lessonSlices and MapsWhat you'll learn
- Slice literal
- Append
- Len
- Indexing
- Range
- Map literal
- Map lookup with ok
- Delete
Read this lesson in your language
All lessons in this course
20 lessons- 1Hello, Go25 min
- 2Variables and Types25 min
- 3Control Flow: if and for30 min
- 4Functions30 min
- 5Slices and Maps35 min
- 6Structs and Pointers35 min
- 7Methods and Interfaces35 min
- 8Error Handling35 min
- 9Modules and Project Structure35 min
- 10Tiny CLI Capstone40 min
- 11A Tour of the Standard Library40 min
- 12Testing and Benchmarks40 min
- 13Goroutines and Channels40 min
- 14Concurrency Patterns45 min
- 15Generics35 min
- 16HTTP Servers45 min
- 17Databases with database/sql45 min
- 18Performance and Profiling40 min
- 19Design Patterns in Go40 min
- 20Deployment and Production45 min
