Consider the strings
string_0 = '%s test'
string_1 = '{} test'
Imagine now the desired output is to return the formatted string using the variable x = 'A'.
For the first case there is an easy and elegant solution:
string_0 %= x
print(string_0)
# A test
Is there something similar for the second case? E.g.
string_1 f= x    # Unfortunately does not work
print(string_1)
# A test
Addressing the comments/responses
- I realise string_1is not an f-string but Python won't allow f-strings with empty expression
- I know f'{x} test'works perfectly well but requires knowingxbefore the creation.
- The formatsolutions is also something I'm familiar with but when comparings = s.format(x)tos %= xI find not very smooth
PS Anticipating the responses, I wanted to edit the above part in my question but was not able due to the simultaneous edit.
 
     
    