skip to content
Alvin Lucillo

Format specifier %#v

/ 1 min read

💻 Tech

Format specifier %#v in Go makes it easier to debug a program by providing details of data structures rather than just using %v.

type Person struct {
	Name string
	Age  int
}

func main() {
	p := Person{Name: "Francois", Age: 100}
	pSlice := []Person{p}
	fmt.Printf("%v\n", p)  // Output: {Francois 100}
	fmt.Printf("%#v\n", p) // Output: main.Person{Name:"Francois", Age:100}
	fmt.Printf("%v\n", pSlice) // Output: [{Francois 100}]
	fmt.Printf("%#v\n", pSlice) // Output: []main.Person{main.Person{Name:"Francois", Age:100}}
}