以下代碼package mainimport ( "fmt")func main() { fmt.Println(say(9))}func say(num int)(total string){return fmt.Sprintf("There are %s reasons to code!", num)}產(chǎn)生以下輸出There are %!s(int=9) reasons to code!我的問(wèn)題我應(yīng)該怎么做才能在字符串中插入一個(gè)數(shù)字?
3 回答

米脂
TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超3個(gè)贊
如果您想始終使用任何類型的“默認(rèn)”表示形式,請(qǐng)使用%v
as in
fmt.Sprintf("There are %v reasons to code!", num)
- 3 回答
- 0 關(guān)注
- 269 瀏覽
添加回答
舉報(bào)
0/150
提交
取消