How to print interface in golang?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

Today, we will see how we can print an interface in the golang console, here we will use the fmt.Println() method to show interface data in the golang console.

First, we have to create an interface with values which we pass in the fmt.Println() method to console it.

Let’s dive into code…

package main
import "fmt"

func main() {
  var x interface{} = []int{1, 2, 3}

Well, when you run above go program you will see array of int. check following image for output.

print, interface, golang

Try it yourself

All the best 👍

Follow me on Twitter