Module 8 · Lesson 1 of 536/50 in the course~10 min
Module lessons (1/5)
`fmt` advanced
Lesson preview5 hands-on exercises readyCourse Go · Module 8 — Essential standard library
Sprintf, Fprintf, %+v and %#v verbs, width and precision formatting, - and 0 flags.
What you'll learn in this lesson
- Correctly choose between
Print*,Fprint*,Sprint*andErrorfbased on the text destination. - Use the diagnostic verbs
%v,%+v,%#v,%T,%q, and the verb%wfor error wrapping. - Control width, alignment, zero-padding and decimal places with flags and precision.
- Route diagnostics and errors to
os.Stderrviafmt.Fprintf.
Overview
The fmt package is the Swiss Army Knife of text I/O in Go. Knowing how to choose between its function families and the right verbs allows you to build readable logs, inspectable error messages, and aligned reports without external dependencies.
The functions of fmt are grouped into four families recognizable by the prefix:
Sections covered in this lesson
- 1The four families of
fmt - 2Diagnostic verbs and
struct - 3Width, padding flags and precision
- 4Error wrapping and custom
io.Writer - 5Guided practice
- 6Check for understanding
Pro Lesson · Module 8 — Essential standard library
Unlock "`fmt` advanced" and the full Course Go curriculum
`Sprintf`, `Fprintf`, `%+v` and `%#v` verbs, width and precision formatting, `-` and `0` flags.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in Course Go plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.