Let’s be honest! What’s wrong with this?

age = 45
name = "Bruce Wayne"

print(name + " was " + str(age) + " years old.")

There’s just too much effort involved! 😂. How many times have quotes been opened and closed, variables have been casted and have had to concatenated? And all this is for just 2 variables!

If you’ve been reading some of the extra links by LearnPythonTheHardWay, you would have seen there was a type of string formatting featured which used a different method of concatenating variables to a string. Now look at the example below.

https://replit.com/@bitFez/ex11#main.py

This example uses a newer feature in Python called f-strings.

The original example had a total of 41 characters typed within the print parenthesis.

This example has a total of 30.

Simple put, Python can use the f-strings method to format all objects into string format as it injects the object.

https://www.youtube.com/shorts/aAePW56r4CI

Tasks