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)
}
Run Code Online (Sandbox Code Playgroud)
我的输出是
There are %!s(int=9) reasons to code!
Run Code Online (Sandbox Code Playgroud)
我应该怎么做才能在字符串中插入一个数字?
met*_*ule 40
如果你想一直使用的"默认"表示不管是什么类型,使用%v
如
fmt.Sprintf("There are %v reasons to code!", num)
Run Code Online (Sandbox Code Playgroud)