fmt
The Go standard library package for formatted input and output, such as printing text with fmt.Println and fmt.Printf.
In more detail
Its print functions come in families: Print writes to standard output, Sprint returns a string, and Fprint writes to any io.Writer such as os.Stderr. The f versions take a format string with verbs such as %s and %d. fmt.Errorf builds error values the same way.
Example
import "fmt"Related terms
- fmt.Println — The fmt function that prints its arguments to standard output separated by spaces and followed by a new line.
- fmt.Printf — The fmt function that prints text built from a format string, in which verbs such as %s and %d are replaced by the arguments.
- fmt.Sprintf — The fmt function that builds a string from a format string and arguments and returns it instead of printing it.
- fmt.Fprintf — The fmt functions that write formatted text to a destination you choose, such as os.Stderr, a file or an HTTP response.
- format verb — A placeholder starting with % in a format string, such as %s or %d, that says how to print the matching argument.
- fmt.Errorf — The fmt function that creates an error with a formatted message, and wraps another error inside it when you use the %w verb.
Taught in
- What Go Is and Why It Matters — Concurrent Systems Programming with Go
- Installing the Go Toolchain — Concurrent Systems Programming with Go
- Go Workspaces and Modules — Concurrent Systems Programming with Go
- Your First Program and go run — Concurrent Systems Programming with Go
- Variables, Typing, and Zero Values — Concurrent Systems Programming with Go
- Pointers and Memory — Concurrent Systems Programming with Go
- Arrays, Slices, and Maps — Concurrent Systems Programming with Go
- Structs and Methods — Concurrent Systems Programming with Go