An addition to f-strings:
a = 1
b = 1
print(f'{a+b}') # '2'
print(f'{a+b=}') # 'a+b=2'
# I suggest adding this too
print(f'{=a+b}') # 'a+b'
It is different from putting it in quotes in a way how editors interpret it.
E.g. changing the variable name in PyCharm would unambiguously change f-string
as well, while it would not change the string literal.
Also, one could argue that it can just be extracted by
`fâ{a+b=}â.split(â=â)[0]`, but it is of course sub-optimal given the
possibility that evaluation is expensive and not required.
DG.
> On 12 Sep 2023, at 13:06, Chris Angelico <[email protected]> wrote:
>
> On Tue, 12 Sept 2023 at 20:05, Dom Grigonis <[email protected]> wrote:
>>
>> Please read the next part of my e-mail too. It actually answer your question.
>>
>
> I did read it, and it didn't answer the question. Your desired
> semantics are not clear.
>
> ChrisA
> _______________________________________________
> Python-ideas mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/[email protected]/message/P5RHZPHTVREEYOG2VSBZYLA6UU33T2X3/
> Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/6VVOWCY253PZPMTYNCEXGLH46YDAXN6S/
Code of Conduct: http://python.org/psf/codeofconduct/