🚀 Get 25% off access to all my premium courses - use discount code FUNCMAIN at checkout - view the pricing page now!

Video:

Arrays and Slices in Go

May 8, 2021

Course Instructor: Elliot Forbes

Hey Gophers! My name is Elliot and I'm the creator of TutorialEdge and I've been working with Go systems for roughly 5 years now.

Code

package main

import "fmt"

func main() {
	println("Arrays and Slices in Go")

	// [1, 2, 3, 4]
	planets := [8]string{"mercury", "venus", "earth", "mars", "jupiter", "saturn", "uranus", "nepture"}
	fmt.Println(planets)

	var planetsArray [8]string
	planetsArray[0] = "mercury"
	fmt.Println(planetsArray)

	planetSlice := []string{"mercury", "venus", "earth", "mars", "jupiter", "saturn", "uranus", "nepture"}
	fmt.Println(planetSlice)

	var planetSliceVerbose []string
	planetSliceVerbose = append(planetSliceVerbose, "mercury")
	fmt.Println(planetSliceVerbose)
}

Output

$ go run main.go
Arrays and Slices in Go
[mercury venus earth mars jupiter saturn uranus nepture]
[mercury       ]
[mercury venus earth mars jupiter saturn uranus nepture]
[mercury]