How to print map in golang?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

Today, we will create a map variable, add some values, and will try to print it in the console.

Here, we are going to use the fmt.Println() method to print map variable values.

To create a map type variable we write like m := make(map[string]int).

Let’s write code and check the golang console.

package main

import "fmt"

func main() {

    m := make(map[string]int)

    m["k1"] = 7
    m["k2"] = 13

    fmt.Println("map:", m)

In the above code, we have created a map variable and added some data. check the following image for output.

print, map, golang

All the best 👍

Follow me on Twitter