Documentation Index
Fetch the complete documentation index at: https://mintlify.com/golang/go/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Package fmt implements formatted I/O with functions analogous to C’s printf and scanf. The format ‘verbs’ are derived from C’s but are simpler.Printing Functions
There are four families of printing functions:- Print, Println, Printf - write to standard output
- Sprint, Sprintln, Sprintf - return a string
- Fprint, Fprintln, Fprintf - write to an io.Writer
- Append, Appendln, Appendf - append to a byte slice
Printf
Formats according to a format specifier and writes to standard output.Format string with verbs like %v, %d, %s, etc.
Arguments to format according to the format string
Number of bytes written
Any write error encountered
Sprintf
Formats according to a format specifier and returns the resulting string.Format string with verbs
Arguments to format
The formatted string
Fprintf
Formats according to a format specifier and writes to w.Writer to output formatted text to
Format string
Arguments to format
Number of bytes written
Any write error encountered
Values to print
Number of bytes written
Any write error encountered
Println
Formats using default formats, adds spaces between operands and a newline.Scanning Functions
Scanf
Scans text read from standard input, storing values into successive arguments.Format string specifying how to parse input
Pointers to variables to store scanned values
Number of items successfully scanned
Error if scanning failed
Scan
Scans space-separated values from standard input.Sscanf
Scans the argument string, storing values into successive arguments.String to parse
Format string
Pointers to store parsed values
Format Verbs
General
%v- value in default format%+v- adds field names for structs%#v- Go-syntax representation%T- type of the value%%- literal percent sign
Boolean
%t- the word true or false
Integer
%b- base 2%d- base 10%o- base 8%x- base 16, lowercase%X- base 16, uppercase%c- the character%q- quoted character
Floating-point
%f- decimal point, no exponent%e- scientific notation%g- %e for large exponents, %f otherwise
String
%s- string or slice%q- double-quoted string%x- base 16, lowercase%X- base 16, uppercase
Pointer
%p- base 16 notation with leading 0x