[Tutor] To FORMAT or not to

Steven D'Aprano steve at pearwood.info
Mon Jan 4 19:53:51 EST 2016


On Mon, Jan 04, 2016 at 07:50:59PM +0000, Mark Lawrence wrote:
> On 03/01/2016 13:12, Alan Gauld wrote:

[snip unnecessary quoting]

> >There are several reasons although your technique is far from
> >the worst way of doing things. And the format string here would probably
> >be better written as:
> >
> >print("You've visited {0} & {2}.".format(island, new))
[...]

> Three reasons for why it's better but it doesn't actually work as given.

Mark, please don't bottom-post. That has all the disadvantages of 
top-posting, and none of the advantages. (In other words, it is *worse* 
than top-posting.) Instead, you should trim your quoting and post 
inline.


> >>> island = "Isle Of Wight"
> >>> new = "Isle of Wong"
> >>> print("You've visited {0} & {2}.".format(island, new))
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> IndexError: tuple index out of range

I think that's an obvious typo that should be {1} instead of {2}.


-- 
Steve


More information about the Tutor mailing list