What Does F String Do in Python: Master String Formatting Now

Logan Jul 13, 2026

In the dynamic world of Python programming, the introduction of f-strings, or formatted string literals, has significantly enhanced the ease and readability of string formatting. But what exactly do f-strings do?

string methods in python
string methods in python

F-strings, introduced in Python 3.6, provide a convenient way to embed expressions inside string literals, using curly braces {}. They are a stark improvement over the traditional methods of string formatting like printf-style strings and str.format() method, due to their readability and conciseness.

Python string slicing cheat sheet
Python string slicing cheat sheet

How F-strings Work

At their core, f-strings are literacy string literals prefixed with 'f'. The expressions inside the curly braces { expr } are replaced with their values.

Useful string methods for python
Useful string methods for python

Consider this simple example: 'f' = 10, then `f"My favorite number is {f}"` resolves to 'My favorite number is 10'.

Expressions in F-Strings

a red neon sign with the words f and f in different font styles on it
a red neon sign with the words f and f in different font styles on it

F-strings support a variety of expressions, not just simple variables. You can embed arithmetic operations, function calls, and even if-else statements.

For example, `f"sqrt(16) = {2 ** 0.5} and squared = {(2 ** 0.5) ** 2}"` will output 'sqrt(16) = 2.0 and squared = 4.0'.

Formatting in F-Strings

a screenshot of what are f - strings in python text on a black background
a screenshot of what are f - strings in python text on a black background

F-strings also support formatting options like padding, aligning, and limiting the width of values.

For instance, `f"{ 동작 }".rjust(20)` will output ' 동작'. Here, the empty string ' ' is used to pad the left side of '동작' so the total width is 20 characters.

The Power of F-Strings: Use Cases

How to Reverse A String in Python?
How to Reverse A String in Python?

F-strings shine in situations where you need to embed complex expressions or present tabular data in your strings.

Their ability to break down complex strings into small, manageable chunks of data makes them an invaluable tool in many scenarios.

All Important Python Functions for Beginners (Complete Cheat Sheet)
All Important Python Functions for Beginners (Complete Cheat Sheet)
a screenshot of a programming program with the text what is an f - string in python?
a screenshot of a programming program with the text what is an f - string in python?
Python String Method
Python String Method
Master Python Strings: Essential Concepts Every Beginner Should Learn
Master Python Strings: Essential Concepts Every Beginner Should Learn
Converting an Integer to a String in Python
Converting an Integer to a String in Python
3 ways to trim a String in Python - AskPython
3 ways to trim a String in Python - AskPython
10 Python String Methods Every Beginner Should Know
10 Python String Methods Every Beginner Should Know
Master Python String Functions with These Essential Tips
Master Python String Functions with These Essential Tips
python string method input method output
python string method input method output
How to Lowercase Python String with Example Programs
How to Lowercase Python String with Example Programs
an image of a computer screen with the words python string method in red and black
an image of a computer screen with the words python string method in red and black
a poster with the words string method in python
a poster with the words string method in python
15 Essential Python String Functions Every Beginner Must Know (Python Cheat Sheet)
15 Essential Python String Functions Every Beginner Must Know (Python Cheat Sheet)
Python F-String: 73 Examples to Help You Master It
Python F-String: 73 Examples to Help You Master It
Python String Methods
Python String Methods
what are t - strings in python?
what are t - strings in python?
python string method
python string method
a computer screen with the words how to use python - strings? and an image of a
a computer screen with the words how to use python - strings? and an image of a
How to Use the String join() Method in Python
How to Use the String join() Method in Python
Python important methods - Programming
Python important methods - Programming

Embedding Complex Expressions

F-strings simplify embedding complex expressions into strings. By breaking down the expression and the string into smaller manageable parts, they make the code easier to read, write, and maintain.

For example, `f"Pi is approximately {22 / 7}"` demonstrates this where the complex expression is clearly defined and replaces the curly braces.

Presenting Tabular Data

F-strings also excel in presenting tabular data. They allow you to neatly align columns, leading to cleaner, easier-to-read outputs.

Consider `f"{'Name':<10} {'Age':<5} 'John Doe' {33}"` which outputs 'Name Age John Doe 33' with neat alignment.

The versatility and readability of f-strings have made them a game-changer in Python's handling of strings. They are a powerful tool in any programmer's kit, simplifying code, boosting readability, and improving overall productivity.