Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102099 > unrolled thread

Re: Re[2]: .format won't display my value with 2 decimal places: Why?

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2016-01-25 10:31 -0700
Last post2016-01-25 10:31 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Re[2]: .format won't display my value with 2 decimal places: Why? Ian Kelly <ian.g.kelly@gmail.com> - 2016-01-25 10:31 -0700

#102099 — Re: Re[2]: .format won't display my value with 2 decimal places: Why?

FromIan Kelly <ian.g.kelly@gmail.com>
Date2016-01-25 10:31 -0700
SubjectRe: Re[2]: .format won't display my value with 2 decimal places: Why?
Message-ID<mailman.224.1453743160.15297.python-list@python.org>
On Mon, Jan 25, 2016 at 10:19 AM, MRAB <python@mrabarnett.plus.com> wrote:
>
>
> On 2016-01-25 16:51:36, "Ian Kelly" <ian.g.kelly@gmail.com> wrote:
>
>>
>> Why doesn't str.format raise an exception when passed extra positional
>> arguments?
>>
> That format string uses auto-numbering, and it's equivalent to 'The new
> price is {0:.2f}'.
>
> In general, the positional arguments can be used in any order, and there can
> also be keyword arguments, so it would need to remember which arguments had
> been used. Would it be worth it?
>
> Do you really want to insist that the format string always used _all_ of the
> arguments?

Good point, that makes sense. For example, I would expect this to work:

'{0} {2}'.format(*some_list)

as long as some_list has three elements. I wouldn't expect it to fail
just because the middle element is unused, so why should it fail if
there are trailing elements that are unused?

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web