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)
F-strings are your friend!
Definitely! :D