*printf series functions support format formatting parameters. Here, we categorize according to the data type of the variables replaced in the placeholders for easy lookup and memorization.

Placeholder List

CategoryPlaceholderDescription
General Placeholder%vDefault format representation of the value
%+vSimilar to %v, but adds field names when printing structs
%#vGo-syntax representation of the value
%TPrint the type of the value
%%Percent sign
Boolean%ttrue or false
Integer%bRepresented in binary
%cThe Unicode code point for the value
%dRepresented in decimal
%oRepresented in octal
%xRepresented in hexadecimal (using a-f)
%XRepresented in hexadecimal (using A-F)
%URepresented in Unicode format: U+1234, equivalent to U+%04X
%qQuoted Go-syntax character literal of the value, with possible escapes for safety
Floating Point and Complex%bScientific notation with binary exponent, e.g.: -123456p-78
%eScientific notation, e.g.: -1234.456e+78
%EScientific notation, e.g.: -1234.456E+78
%fDecimal point but no exponent, e.g.: 123.456
%FEquivalent to %f
%gUses %e or %f format depending on the situation for more concise and accurate output
%GUses %E or %F format depending on the situation for more concise and accurate output
String and []byte%sDirectly outputs the string or []byte
%qDouble-quoted Go-syntax string literal, with possible escapes for safety
%xRepresented in two-character hexadecimal for each byte (using a-f)
%XRepresented in two-character hexadecimal for each byte (using A-F)
Pointer%pHexadecimal representation with 0x prefix
Width Specifier%fDefault width, default precision
%9fWidth 9, default precision
%.2fDefault width, precision 2
%9.2fWidth 9, precision 2
%9.fWidth 9, precision 0
Placeholder Modifiers+Always show sign for numeric values; for %q (%+q) generates ASCII-only output (with escapes)
 Space, prefixes positive numbers with a space and negative numbers with a sign; for %x or %X (% x or % X), inserts spaces between printed bytes
-Pads the right instead of the default left (right-align to left-align switch)
#Prefixes octal with 0 (%#o), hexadecimal with 0x (%#x) or 0X (%#X), strips 0x for pointers (%#p); for %q (%#q) and %U (%#U), outputs Go literal with quotes and spaces
0Pads with 0 instead of spaces, placed after sign for numeric types

References