How to print slice in golang?
April 28, 2022Hi 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 in
fmt.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]
All the best π