Nothing bad will happen, but the %d
verb instructs the fmt
package to print is as a number (using base 10), and the %v
verb means to use the default format which can be overridden.
See this example:
type MyInt intfunc (mi MyInt) String() string {
return fmt.Sprint("*", int(mi), "*")
}func main() {
var mi MyInt = 2
fmt.Printf("%d %v", mi, mi)
}
【为什么不用%v打印int和string】Output:
2 *2*
推荐阅读
- 【golang】leetcode中级-字母异位词分组&无重复字符的最长子串
- 彻底理解Golang Map
- kratos线上开源年会它来啦~
- 深入浅出 Golang 资源嵌入方案(go-bindata篇)
- 深入浅出 Golang 资源嵌入方案(前篇)
- golang 经典案例总结
- Go实战 | 基于有向无环图的并发执行流的实现
- Golang 数组和切片
- Go JSON编码与解码()
- golang map基础知识