Python: Going Beyond Basic String Formatting using f-string

Faster and More Efficient String Formatting with Python’s f-Strings

Pravash
5 min readMar 20, 2023

--

Python f-string

Hi Everyone! In this article I will discuss about the python f-string — A new feature which was introduced in Python 3.6 and this feature quickly became the talk of the programming world and revolutionized the way developers format strings.

I will discuss this topic in more informal style and also will explain this with examples, which will help you to get to know about it and use it in day to day coding.

Intro

An f-string is a string literal that is prefixed with the letter “f”. It allows developers to embed expressions inside string literals, using curly braces {}. These expressions are evaluated at runtime and the resulting values are inserted into the string.

Getting Started

Some of you may know about it but what you may not is that there’s a lot of extra stuff that can be put in between these curly braces.

For example, consider the following code snippet:

This example contains like how you can do debug and add Arbitrary expressions in f-string.

name = "John"
age = 30
num_val = 10
print(f"My name is {name} and I…

--

--

Pravash
Pravash

Written by Pravash

I am a passionate Data Engineer and Technology Enthusiast. Here I am using this platform to share my knowledge and experience on tech stacks.

Responses (1)