比如这么写:
fmt.Println("Hello, playground %d",i)
那么会出现warning:Println call has possible formatting directive %d Go vet exited.
fmt.Println
doesn't do formatting things like %d
. Instead, it uses the default format of its arguments, and adds spaces between them.
fmt.Println("Hello, playground",i) // Hello, playground 5
If you want printf style formatting, use fmt.Printf
.
fmt.Printf("Hello, playground %d\n",i)
And you don't need to be particular about the type. %v
will generally figure it out.
fmt.Printf("Hello, playground %v\n",i)