Consider,
package main
import "fmt"
func main() {
name := "johnny"
fmt.Println("Hello world %s
", name)
}
prints out,
Hello world %s johnny
Why do I get the %s instead of this,
package main
import "fmt"
func main() {
name := "johnny"
fmt.Printf("Hello world %s
", name)
}
which prints Hello world johnny?
I have tried to figure out the answer from the documentation,
If the format (which is implicitly %v for Println etc.) is valid for a string (%s %q %v %x %X), the following two rules apply:
If an operand implements the error interface, the Error method will be invoked to convert the object to a string, which will then be formatted as required by the verb (if any).
If an operand implements method String() string, that method will be invoked to convert the object to a string, which will then be formatted as required by the verb (if any).
But I'm having trouble understanding if this is affecting my program.