Sprintf

You might have seen things like fmt.Println("some string") andvariations around it. But sometimes you might want to just generatea string using the formatting tools found under fmt without itnecessarily going out on stdout. That's whatfmt.Sprintf is for.

Python

  1. max = 10
  2. raise Exception("The max. number is {}".format(max))

Go

  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6. max := 10
  7. panic(fmt.Sprintf("The max. number is %d", max))
  8. }