Formatting Operators Flashcards
Notes: (1) The alternate form causes a leading zero ("0") to be inserted between left-hand padding and the formatting of the number if the leading character of the result is not already a zero. (2) The alternate form causes a leading '0x' or '0X' (depending on whether the "x" or "X" format was used) to be inserted between left-hand padding and the formatting of the number if the leading character of the result is not already a zero. (3) The alternate form causes the result to always cont
Conversion type %d
Signed integer decimal
(same as %i but %d is used more often)
Conversion %f
Floating point decimal format.
note: The alternate form causes the result to always contain a decimal point, even if no digits follow it.
The precision determines the number of digits after the decimal point and defaults to 6.
Conversion %c
Single character (accepts integer or single character string).
What is the fourth conversion specifier component
Minimum field width (optional). If specified as an “*” (asterisk), the actual width is read from the next element of the tuple in values, and the object to convert comes after the minimum field width and optional precision.
Conversion %u
Unsigned decimal.
Conversion %F
Floating point decimal format.
note: The alternate form causes the result to always contain a decimal point, even if no digits follow it.
The precision determines the number of digits after the decimal point and defaults to 6.
Conversion %G
Floating point format. Uses exponential format if exponent is greater than -4 or less than precision, decimal format otherwise.
note: The alternate form causes the result to always contain a decimal point, and trailing zeroes are not removed as they would otherwise be.
The precision determines the number of significant digits before and after the decimal point and defaults to 6.
What is the fifth conversion specifier component
Precision (optional), given as a “.” (dot) followed by the precision. If specified as “*” (an asterisk), the actual width is read from the next element of the tuple in values, and the value to convert comes after the precision.
What is the second conversion specifier component
Mapping key (optional), consisting of a parenthesized sequence of characters (for example, (somename)).
Conversion %
No argument is converted, results in a “%” character in the result.
Conversion %o
Unsigned octal
note: The alternate form causes a leading zero (“0”) to be inserted between left-hand padding and the formatting of the number if the leading character of the result is not already a zero.
What is the third conversion specifier component
Conversion flags (optional), which affect the result of some conversion types.
Conversion %X
Unsigned hexadecimal (uppercase).
Conversion %s
String (converts any python object using str()).
note: If the object or format provided is a unicode string, the resulting string will also be unicode.
The precision determines the maximal number of characters used.
How many possible values can a conversion specifier have
7 (They MUST be in order)