golang 之 Println call has possible formatting directive

比如這麼寫:

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)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章