Being python’s birthday today, or the anniversary of Guido Van Rossum’s announcement of python, I figured I’d post something cool for the community. There actually isn’t an F string on a standard tuning guitar, but I thought it would be a neat photo for the F string!
F strings in python3 can be very powerful and useful when dealing with complex strings. Often times we find ourselves struggling to piece together information to deliver it in a particular string format. Or if you’re like me, being able to customize a string for proper logging is critical.
In python 2, you had the ever popular str method, along with string concatenation to help you achieve this. I mean, it works. It doesn’t give you the full control you may need however. It’s much nicer to be able to type out what you need and have the interpreter handle the online declaration and code logic on the fly:
Fire TV Stick with all-new Alexa Voice Remote, streaming media player Price $ 29.99import math
print(f'This is the area of my circle: {math.pi * 2*2}')
It becomes much easier to write your code for creating strings without having to worry about concatenation issues. Just write the code you already know the syntax for, and wrap it around a string. No more looking up documentation on the string for matter you’re using.
Make Money Online Selling Domain Names! Click Here To Find out How
What about saving a few cpy cycles? Might not seem like a big deal in the great scheme of things, but removing method calls to str removing the need for concatenation does improve your code performance, and as mentioned before, probability of syntax errors. Just call the variables you need inside the curly braces:
num = 3
print(f'I just had {num} slices of pizza!')
As you can see, using f strings in python3 is not only easy, but extremely convenient!