Syntax

Go Create a Slice Syntax

In Go, create a slice: creates a resizable list — nums := []int{1, 2, 3} nums = append(nums, 4)

Quick Answer

Syntax
nums := []int{1, 2, 3} nums = append(nums, 4)
GoSyntax

Create a Slice

Code example
nums := []int{1, 2, 3} nums = append(nums, 4)

Creates a resizable list.

Learn More

How to create a slice in Go

  1. Open your Go file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Go Create a Slice Syntax

Use nums := []int{1, 2, 3} nums = append(nums, 4).

Related Syntax References

Frequently asked questions

What is the Go syntax for create a slice?

Use this pattern: nums := []int{1, 2, 3} nums = append(nums, 4)

Can I copy this Go code example?

Yes. Use Copy code and adapt the example to your program.

Is this Go syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify