gogofmt

how print variable values in Go with fmt.Printl?


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)
    }