Formatting with Package "fmt"
Explore how to format output and input in Go using the fmt package. Understand format verbs, printing to console or files, string formatting, and reading input from standard input or streams.
The fmt package
Here is a list of features provided by the fmt package:
- Format things like basic strings and values.
- Print data to the console.
- Collect user input from the console.
- Write into a file using a writer.
- Print error messages.
Templates
The fmt package relies on the concept of a format template. Essentially, this is only a string that contains the text we want to manage plus some placeholders called verbs that tell fmt the format and where to insert our variables.
Verbs
There are a lot of verbs that are provided by the fmt package, including:
%vis a generic placeholder that we can use