Sujet : Re: Flubbed it in the second interation through the string: range error... HOW?
De : list1 (at) *nospam* tompassin.net (Thomas Passin)
Groupes : comp.lang.pythonDate : 29. May 2024, 13:54:09
Autres entêtes
Message-ID : <mailman.59.1716985154.2909.python-list@python.org>
References : 1 2 3 4
User-Agent : Mozilla Thunderbird
On 5/29/2024 3:14 AM, Chris Angelico via Python-list wrote:
On Wed, 29 May 2024 at 16:03, Cameron Simpson via Python-list
<python-list@python.org> wrote:
By which Thomas means stuff like this:
>
print(f'if block {name[index]} and index {index}')
>
Notice the leading "f'". Personally I wouldn't even go that far, just:
>
print('if block', name[index], 'and index', index)
>
But there are plenty of places where f-strings are very useful.
I wouldn't replace str.format() everywhere, nor would I replace
percent encoding everywhere - but in this case, I think Thomas is
correct. Not because it's 2024 (f-strings were brought in back in
2015, so they're hardly chronologically special),
I only meant that they have been around for 9 years and are usually more readable, so just change over already. I had some inertia over them myself (imagine sticking with % formatting!) so I understand.
but because most of
this looks like debugging output that can take advantage of this
feature:
print(f"if block {name[index]=} {index=}")
ChrisA