F-String Formatting In Python

Introduction

What Is String Formatting?

Displaying Variables

We previously use the str.format() method mostly to format the strings. But, the time has changed we have a new method to make our efforts twice as fast.

Expressions

What if we can evaluate expressions like arithmetic, function calls, etc., in a string? f-string allows us to evaluate expressions inside the string.

Special Characters

What if we want to display special characters like {}, \’, \”?, which are internally used by Python for special meaning. Can we use escape character inside the f-string? Let’s see the answers to these questions.

Dictionaries

We have to be a bit careful while dealing with dictionary keys inside the f-string. We have to use a different quotation to the dictionary key & f-string. We are not permitted to use the same quotations for a dictionary key as if it was an f-string.

Data Scientist & Machine Learning Engineer