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

1
Q

Conversion type %d

A

Signed integer decimal

(same as %i but %d is used more often)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Conversion %f

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Conversion %c

A

Single character (accepts integer or single character string).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the fourth conversion specifier component

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Conversion %u

A

Unsigned decimal.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Conversion %F

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Conversion %G

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the fifth conversion specifier component

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the second conversion specifier component

A

Mapping key (optional), consisting of a parenthesized sequence of characters (for example, (somename)).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Conversion %

A

No argument is converted, results in a “%” character in the result.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Conversion %o

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the third conversion specifier component

A

Conversion flags (optional), which affect the result of some conversion types.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Conversion %X

A

Unsigned hexadecimal (uppercase).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Conversion %s

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How many possible values can a conversion specifier have

A

7 (They MUST be in order)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Conversion %e

A

Floating point exponential format (lowercase).

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.

17
Q

Conversion %x

A

Unsigned hexadecimal (lowercase).

18
Q

Conversion %E

A

Floating point exponential format (uppercase).

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.

19
Q

Conversion type %i

A

Signed integer decimal

20
Q

Conversion %r

A

String (converts any python object using repr()).

The %r conversion was added in Python 2.0.

The precision determines the maximal number of characters used.

21
Q

Conversion %g

A

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.

22
Q

What is the sixth conversion specifier component

A

Length modifier (optional).

23
Q

What is the first conversion specifier component

A
  1. The “%” character, which marks the start of the specifier.
24
Q

What is the seventh conversion specifier component

A

Conversion type.