Python print statement with f-string

Python is very easy to read and write can understandable by non-programmer it is just like the English language.

In this tutorial just looking into the f-string in the print statement.

For example:

>>> name = john,

>>> age = 27,

>>> occupation = singer

>>> print("%s is %d years old"%(name,age))

>>>print("{}is years old".format(name,age))

>>>print(f'{name} is {age} years old')

The f string has the f — prefix and uses flower brackets to evaluate values.

Format specifier does typecast, padding, and aligning are specified after the colon character just like the above-mentioned example.

python f-string used with expressions, dictionaries, debugging, multi lining alignment, calling a function, format DateTime, formats floating values, to specify the width of the column, in justifying the string characters.

For more information: https://zetcode.com/python/fstring/

--

--

Jyothi Panuganti

Data Science Enthusiast, Blogger, content writer, and Freelancer.