String Formats Flashcards
%d
%d is used as a placeholder for numeric decimal values.
Outputs the number in base 10
%i
%i is used as a placeholder for numeric or decimal values.
Signed integer decimal.
%o
%o is used as a placeholder for Octal format.
Outputs the number in base 8.
%u
Obsolete type – it is identical to ‘d’.
%x
%x is used as a placeholder for Hex format
lowercase characters.
Outputs the number in base 16, using lower- case letters for the digits above 9.
%X
%X is used as a placeholder for Hex format
UPPERcase characters.
Outputs the number in base 16, using upper- case letters for the digits above 9.
%e
%E is used as a placeholder for Exponent notation.
Floating point exponential format (lowercase).
usually base power 10 or 2
An approx or undefined number, presented as a range of numbers which it can be taken from. This number will have a power/factor allocated to it usually base power 10 or 2
%E
%E is used as a placeholder for Exponent notation.
Floating point exponential format (uppercase).
Same as ‘e’ except it uses an upper case ‘E’ as the separator character.
An approx or undefined number, presented as a range of numbers which it can be taken from. This number will have a power/factor allocated to it usually base power 10 or 2
%f
%f is used as a placeholder for Fixed point. Displays the number as a fixed-point number. The default precision is 6.
A fixed decimal number with a power/factor usually base power 10 or 2
%F
%F is used as a placeholder for Fixed point. Same as ‘f’, but converts nan to NAN and inf to INF.
A fixed decimal number with a power/factor usually base power 10 or 2
%g
%g is used as a placeholder for Floating point format.
Uses lowercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise.
An approx or undefined number, presented as a range of numbers which it can be taken from.
%G
%G is used as a placeholder for Floating point format.
Uses uppercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise.
An approx or undefined number, presented as a range of numbers which it can be taken from.
%s
%s is used as a placeholder for string values you want inject into a formatted string.
Converts any non string to string using str()
%r
%r is used as a placeholder for an unspecified number or random number
i.e. when program requires user input for a number so does not know it yet
Converts any non string to string using repr()
%b
%b is used as a placeholder for Binary numeric values.
Outputs the number in base 2.