-2

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.

jimmy
  • 457
  • 5
  • 20

2 Answers2

0
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)
}
Pratheesh M
  • 1,028
  • 6
  • 13
-2

What you need is Sprintf

You can find already an example there.

Since you want to print an integer, you can use the %d modifier.

Keep in mind that Sprintf family does not insert newline automatically, so you will also need \n

gpopides
  • 718
  • 5
  • 13