[Tutor] Asterisk
Michael Powe
michael@trollope.org
Thu Dec 5 01:41:02 2002
On Wed, Dec 04, 2002 at 11:39:30PM -0330, Adam Vardy wrote:
>
> Wednesday, December 4, 2002, 9:53:09 PM, you wrote:
>
> >> This formatting statement includes the moderately advanced '*' token. This
> >> indicates that a number, provided in the 'arguments' will be substituted for
> >> this asterisk. If there are more than one asterisks in a formatting
> >> statement, the first number will be used for the first asterisk, the second
> >> for the next, and so on.
>
> So then, what you say is 6 is not printed because it has already been
> 'used up' somehow? That is, 6 digits of some kind, and 3 fractional
> digits. And then you have the number that is left over, which is
> actually used for the expression?
The 6 means 'place a total of six characters to the left of the decimal point.'
remember that a space is also a char. the most obvious example of how you
would want to use this feature is in lining up the decimal points of a column
of numbers. you have a varying number of numerals to the left of the decimal
point, so you use a formatting command like the 6 to insure that every item
in your column of numbers will take up 6 spaces.
1234.67
123456.89
123.45
1.23
each item in this column has 6 characters, decimal, 2 characters. the tricky part
is remembering that 'space' is a character, too. adding these spaces is sometimes
referred to as padding. in c, you can pad numbers with zeroes, as well. i am sure
you can do the same in python. (you are more likely to use zeroes on the right side
of the decimal, of course.)
mp
"ni!"