//Prints the formatted string
fmt.Printf("format",value1, value2, ...)
//Returns the formatted string
s := fmt.Sprintf("format",value1, value2, ...)
|
Default format
|
%v
|
[4.13 7.13]
|
|
Golang syntax
|
%#v
|
[]float64{4.13, 7.13}
|
|
The type of the value
|
%T
|
[]float64
|
|
Memory address
|
%p
|
0xc00000713f
|
|
Boolean as true / false
|
%t
|
true
|
|
Base 10
|
%d
|
13
|
|
Always show sign
|
%+d
|
+13
|
|
Right padding with spaces
|
%4d
|
__13
|
|
Left padding with spaces
|
%-4d
|
13__
|
|
Pad with zeros
|
%04d
|
0013
|
|
Binary representation
|
%b
|
1101
|
|
Octal representation
|
%o
|
15
|
|
Octal representation with leading 0o
|
%O
|
0o15
|
|
Hex representation, lowercase
|
%x
|
d
|
|
Hex representation, uppercase
|
%X
|
D
|
|
Hex representation with leading 0x
|
%#x
|
0xf
|
|
The unicode character
|
%c
|
A
|
|
The unicode code point
|
%U
|
U+0041
|
|
Scientific format
|
%e
|
7.134130e+02
|
|
With decimal point
|
%f
|
713.413000
|
|
Fixed precision
|
%.2f
|
713.41
|
|
Left padding with spaces
|
%8.2f
|
__713.41
|
|
Automatic decimal count
|
%g
|
713.413
|
|
Character
|
%c
|
D
|
|
Quoted character
|
%q
|
'D'
|
|
Unicode code
|
%U
|
U+0044
|
|
Unicode code and character
|
%#U
|
U+0044 'D'
|
|
Plain string
|
%s
|
Gopher
|
|
Left padding with spaces
|
%10s
|
____Gopher
|
|
Right padding with spaces
|
%-10s
|
Gopher____
|
|
Quoted string
|
%q
|
"Gopher"
|
|
Hex dump
|
%x
|
476f70686572
|
|
Hex dump with spaces
|
% x
|
47 6f 70 68 65 72
|
|
Hex dump, uppercase
|
%X
|
476F70686572
|
|
Hex dump with spaces, uppercase
|
% X
|
47 6F 70 68 65 72
|
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.