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.
In more detail
Printf does not add a new line; end the format with \n. The verbs must match the argument types, and go vet warns when they do not. Use it when you want control over the layout of a line.
Example
fmt.Printf("host %s port %d\n", t.Host, t.Port)Related terms
- format verb — A placeholder starting with % in a format string, such as %s or %d, that says how to print the matching argument.
- fmt.Sprintf — The fmt function that builds a string from a format string and arguments and returns it instead of printing it.
- go vet — The go subcommand that looks for code that compiles but is probably wrong, such as a print format verb that does not match its argument.
- fmt — The Go standard library package for formatted input and output, such as printing text with fmt.Println and fmt.Printf.
Taught in
- Installing the Go Toolchain — 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
- Files and the os Package — Concurrent Systems Programming with Go
- Parsing Arguments with flag — Concurrent Systems Programming with Go