How to print slice in golang?

Hi Friends πŸ‘‹,

Welcome To aGuideHub! ❀️

Today, we are going to create and print slices in golang, here we will use the fmt.Printf() method to print slices in golang.

First, we will create a slice of string and store it in a variable.

Then we will use the β€œ%v”verb infmt.Printf()` to print a slice of data.

Let’s dive into code.

package main
import "fmt"

func main() {
	s := []string{"foo", "bar", "baz"}
	fmt.Printf("%v", s)

When you run the above code, you will get an output something like the below.

[foo bar baz]

print, struct, golang

Try it yourself

All the best πŸ‘

Follow me on Twitter