String Formats Flashcards
%r
Repr format (debugging format).
…”%r” % int == “<type ‘int’>”
%s
String format.
…”%s there” % ‘hi’ == ‘hi there’
%c
Character format.
…”%c” % 34 == ‘ “ ‘
%d
Decimal integers (not floating point).
…”%d” % 45 == ‘45’
%i
Decimal integers (not floating point).
…”%i” % 45 == ‘45’
%u
Unsigned decimal.
…”%u” % -1000 == ‘-1000’
%o
Octal number
…”%o” % 1000 == ‘1750’
%x
Hexadecimal lower case.
…”%x” % 1000 == ‘3e8’
%X
Hexadecimal upper case.
…”%X” % 1000 == ‘3E8’
%e
Exponential notation, lower case ‘e’.
…”%e” % 1000 == ‘1.000000e+03’
%E
Exponential notation, upper case ‘E’.
…”%E” % 1000 == ‘1.000000E+03’
%f
Floating-point real number
…”%f” % 10.34 == ‘10.340000’
%F
Floating point real number, same as ‘%f’.
…”%F” % 10.34 == ‘10.340000’
%g
Either %e or %f, whichever is shorter
…”%g” % 10.34 == ‘10.34’
%G
Floating-point E or F, whichever is shorter, same as ‘%g’
…”%G” % 10.34 == ‘10.34’