String Formats Flashcards
1
Q
%d
A
decimal integers (not floating point)
“%d” % 45 == ‘45’
2
Q
%i
A
same as %d
“%i” % 45 == ‘45’
3
Q
%o
A
octal number
“%d” % 1000 == ‘1750’
4
Q
%u
A
unsigned decimal
“%u” % -1000 == ‘1000’
5
Q
%x
A
hexadecimal lowercase
“%x” % 1000 == ‘3e8’
6
Q
%x
A
hexadecimal uppercase
“%X” % 1000 == ‘3E8’
7
Q
%e
A
exponential notation, lowercase ‘e’
“%e” % 1000 == ‘1.000000e+03’
8
Q
%E
A
exponential notation, uppercase ‘E’
“%E” % 1000 == ‘1.000000E+03’
9
Q
%f
A
floating point real number
“%f” % 10.34 == ‘10.34’
10
Q
%F
A
same as %f
“%F” % 10.34 == ‘10.34’
11
Q
%g
A
same as %f or %g
“%g” % 10.34 == ‘10.34’
12
Q
%c
A
character format
“%c” % 34 == ‘ “ ‘
13
Q
%r
A
repr format (debugging format)
“%r” % int == “”
14
Q
%s
A
string format
“%s there” % hi == ‘hi there’
15
Q
%%
A
a percent sign
“%g%%” % 10.34 == ‘10.34%’