以下代码
package main
import (
"fmt"
)
func main() {
fmt.Println(say(9))
}
func say(num int)(total string){
return fmt.Sprintf("There are %s reasons to code!", num)
}
产生以下输出
There are %!s(int=9) reasons to code!
我的问题
如何在字符串中插入数字?
最佳答案
如果你想始终使用任何类型的“默认”表示,请使用 %v
,如
fmt.Sprintf("There are %v reasons to code!", num)
关于go - 如何在字符串中插入数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21449341/