0

Is there a way to achieve applying f-strings interpolation dynamically on a string?

For example given the string a = '{len([1])}'

a.interpolate() to give '1'

wjandrea
  • 28,235
  • 9
  • 60
  • 81
hangc
  • 4,730
  • 10
  • 33
  • 66
  • Possible duplicate of [How do I convert a string into an f-string?](https://stackoverflow.com/questions/47339121/how-do-i-convert-a-string-into-an-f-string) – wjandrea Oct 04 '19 at 01:17
  • [This comment](https://stackoverflow.com/questions/42497625/can-i-postpone-defer-the-evaluation-of-f-strings#comment72134685_42497625) explains succinctly why this isn't exactly possible – wjandrea Oct 04 '19 at 01:20

1 Answers1

-2

Try this:

 a = f'{len([1])}'
 print(a)
 #1
ExplodingGayFish
  • 2,807
  • 1
  • 5
  • 14