Python String Formatting

F-String was introduced in Python 3.6, and is now the preferred way of formatting strings.

Before Python 3.6 we had to use the format() method.


F-Strings

F-string allows you to format selected parts of a string.

To specify a string as an f-string, simply put an f in front of the string literal, like this:

Example

Create an f-string:

txt = f"The price is 49 dollars"
print(txt)

Continue reading Python String Formatting