Python 3.6 introduced a new way of formatting Strings called f-Strings.
It’s very practical and I use it all the time. Before f-Strings it was necessary to concatenate the strings which lead to longer and harder to read code.
|
|
What’s even better is that we can write expressions in the braces {} which are evaluated at run-time.
|
|
Sometimes you need to concatenate a List of strings. Bad way would be to iterate over the List and append the word on each iteration. String is an immutable element meaning you would have to create new string each time and if the list is very large this would have very negative effect on performance.
Instead use .join() method.
|
|
First you define the separator and then the object you wish to join. It’s cleaner, shorter and better when it comes to performance.