Menu
Coddy logo textTech

Introduction to Slices

Part of the Fundamentals section of Coddy's GO journey. Lesson 74 of 109.

Slices are flexible, dynamic arrays in Go. Unlike arrays with fixed size, slices can grow or shrink.

Create a slice using square brackets without a size, followed by the type:

numbers := []int{1, 2, 3, 4, 5}
fmt.Println(numbers)

This displays the slice contents:

[1 2 3 4 5]

Access slice elements using index notation (starting from 0):

firstNumber := numbers[0]
fmt.Println(firstNumber)

This displays the first element:

1

Try it yourself

This lesson doesn't include a code challenge.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals

Practice on your own: Online Go compiler