fmt

I/O
import "fmt"

Implements formatted I/O with functions analogous to C's printf and scanf. The most commonly used Go package.

Example

package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
    name := "Go"
    fmt.Printf("Welcome to %s!\n", name)
}

Key Types & Functions

PrintlnPrintfSprintfFprintfErrorfStringer

About fmt

The fmt package (imported as fmt) belongs to the I/O category of Go packages. Implements formatted I/O with functions analogous to C's printf and scanf. The most commonly used Go package.

Go's standard library is one of the language's greatest strengths, providing production-ready implementations for networking, cryptography, encoding, I/O, and more. The fmt package follows Go's philosophy of simplicity and composability — small, focused packages that combine through interfaces like io.Reader and io.Writer.

When using fmt in production, follow Go best practices: handle errors explicitly, use context for cancellation and timeouts, prefer composition over inheritance, and write table-driven tests. The Go documentation at pkg.go.dev provides comprehensive API references and examples for every exported type and function.

Related Packages