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
- max = 10
- raise Exception("The max. number is {}".format(max))
Go
- package main
- import "fmt"
- func main() {
- max := 10
- panic(fmt.Sprintf("The max. number is %d", max))
- }