The best/the most convenient way to format strings in Go is to use fmt.Sprintf() function which is similar to template literals in JavaScript.

  • %s for strings

  • %d for integers

  • %f for floats

  • %.2f for rounded float

  • %v for any value and uses value’s formatting

const name = "Kim"  
const age = 22  
s := fmt.Sprintf("%v is %v years old.", name, age)  
  
// s = "Kim is 22 years old"