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
Back to the full Go cheat sheet