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 πŸ‘

Premium Content

You can get all the below premium content directly in your mail when you subscribe us


Portfolio Template

View | Get Source Code

Cheat Sheets

Cheat Sheets Books are basically Important useful notes which we use in our day-to-day life.

I'm working on some more Cheat Sheets book on Jquery, TypeScript, React js and for other languages. I will send it once it's completed.

Stay tuned working on React Js Cheat Sheets Book

Related Posts