Okay. I get it. When I ran through go playground I missed that type receiver was of pointer type, so I was not sure why it didn't print as mentioned in the docs
Thank you On Thursday, 10 March 2022 at 09:00:49 UTC+5:30 kortschak wrote: > On Wed, 2022-03-09 at 19:16 -0800, Nikhilesh Susarla wrote: > > In https://go.dev/doc/effective_go#printing > > I saw an example for printing our custom string output for the type. > > The code below is from docs. > > func (t *T) String() string { > > return fmt.Sprintf("%d/%g/%q", t.a, t.b, t.c) > > } > > fmt.Printf("%v\n", t) > > > > > > But rather the statement should be this right? fmt.Printf("%v\n", > > t.String()) > > Am I missing something? > > > > When the %v (or %s, %q and others[1]) verbs are used the `String() > string` is used to construct the printed value. > > You can see the logic here[2]. > > [1] > > https://github.com/golang/go/blob/00535b839841227ba60c2de78fbf767088f865bc/src/fmt/print.go#L611 > [2] > > https://github.com/golang/go/blob/00535b839841227ba60c2de78fbf767088f865bc/src/fmt/print.go#L623-L628 > > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/782337ca-4051-414a-a809-a6f88f5ffab1n%40googlegroups.com.