how print variable values in Go with fmt.Printl?

Issue

I have the below code snippet:

x_variable := 12311
fmt.Println("message", "X variable has the value '+x_variable+' printed in the screen now")

How can I make that work?
I’ve tried that in the Go playground but couldn’t figure it out how to print the vaue properly.

Solution

package main

import (
    "fmt"
)

func main() {
    x_variable := 12311
    fmt.Printf("message X variable has the value %d printed in the screen now", x_variable)
}

Answered By – Pratheesh M

Answer Checked By – Marilyn (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.