fmt Verbs & Formatting in Go
From the Go cheat sheet ยท String Formatting ยท verified Jul 2026
fmt Verbs & Formatting
Printf verbs and string formatting functions
go
// Common verbs
fmt.Printf("%v", val) // Default format
fmt.Printf("%+v", s) // Struct with field names
fmt.Printf("%#v", s) // Go-syntax representation
fmt.Printf("%T", val) // Type of value
fmt.Printf("%d", 42) // Integer
fmt.Printf("%s", "hi") // String
fmt.Printf("%f", 3.14) // Float
fmt.Printf("%t", true) // Boolean
fmt.Printf("%p", &val) // Pointer
// Sprintf returns string
msg := fmt.Sprintf("Hello, %s!", name)๐ฏ %v is the go-to verb โ works with any type
๐ก %+v shows struct field names โ great for debugging
๐ Sprintf returns a string, Printf writes to stdout
โก Implement String() method to customize %v output