DEV Community

Ashwini Manoj
Ashwini Manoj

Posted on

4

TIL about formatted strings that was introduced in Python 3.6

If you want an easy way to format strings, using formatted strings would be a good way to go! I came across it here when trying to refactor an old code of mine from python2 to python3.

Here's how I was doing string manipulation when I first started off with python:

val = 'This ' + str(a) + ' here multiplied by ' + str(b) + ' = ' + str(a*b)

And now I have learned to do this:

val = f'This {a} here multiplied by {b} = {a*b}'

So much easier to read!

Top comments (2)

Collapse
 
iceorfiresite profile image
Ice or Fire

F-strings are your friend!

Collapse
 
ashwinimanoj profile image
Ashwini Manoj

Definitely! :D

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay