Posts

Showing posts with the label fstrings

Printing variables using f-strings in python

Image
Printing the values of variables is required. It may serve as an output for user to read or for the developers who are debugging their code. Sometimes we need the printed output to be easier to understand and not just a set of variable values . Using formatted string literals or f-strings is by far the most intuitive way to print out variables along with intermittent text. The simple example of printing using f-strings is as follows: a = 2 b = 3 print(f'The value of a is {a}, and the value of b is {b}.') The value of a is 2 and the value of b is 3.