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}
	fmt.Println(x)
}

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 👍

Premium Content

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

Books

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