---
title: "What is F-Strings in python?"  
description: "What is F-Strings in python?"  
author: "ICSM Computer"  
published: 2025-09-16  
updated: 2025-09-17  
canonical: https://www.mindstick.com/forum/161913/what-is-f-strings-in-python  
category: "python"  
tags: ["python-3.4", "Python 3"]  
reading_time: 2 minutes  

---

# What is F-Strings in python?

## What is F-Strings in python, explain with example?

## Replies

### Reply by Anubhav Sharma

## What are F-Strings?

- **F-strings** (formatted string literals) were introduced in **Python 3.6**.
- They let you embed **expressions** inside string literals, using `{}`.
- They start with a prefix `f` or `F`.

Example:

```python
name = "Anna"
age = 25
print(f"My name is {name} and I am {age} years old.")
# Output: My name is Anna and I am 25 years old.
```

## Why Use F-Strings?

- Cleaner and faster than `.format()` or `%` formatting.
- You can write **expressions directly inside** `{}`.

## Example:

```python
x = 10
y = 20
print(f"{x} + {y} = {x + y}")
# Output: 10 + 20 = 30
```

## Features of F-Strings

### 1. Expressions inside {}

```python
print(f"Square of 5 is {5**2}")
# Output: Square of 5 is 25
```

### 2. Function calls inside {}

```python
def greet(name):
    return f"Hello, {name}!"

print(f"{greet('Anna')}")
# Output: Hello, Anna!
```

### 3. Formatting numbers

```python
pi = 3.14159265
print(f"Pi rounded to 2 decimals: {pi:.2f}")
# Output: Pi rounded to 2 decimals: 3.14
```

### 4. Date formatting

```python
from datetime import datetime
today = datetime.now()
print(f"Today is {today:%d-%m-%Y}")
# Output: Today is 17-09-2025  (example)
```

### 5. Debugging (Python 3.8+)

You can append `=` inside `{}` to print both the expression and its value:

```python
x = 5
print(f"{x=}")
# Output: x=5
```

## Performance

> F-strings are **faster** than `.format()` and `%` formatting because they are evaluated at **runtime** and don’t need extra function calls.

Example:

```python
name = "Anna"
age = 25
# Old style
print("My name is %s and I am %d" % (name, age))
# str.format()
print("My name is {} and I am {}".format(name, age))
# F-string
print(f"My name is {name} and I am {age}")
```

## Read More -

- [What is difference between casefold() vs lover() in python?](https://www.mindstick.com/interview/34373/what-is-difference-between-casefold-vs-lover-in-python)
- [What is Python Casting with example?](https://www.mindstick.com/interview/34372/what-is-python-casting-with-example)
- [Explain the Python Strings](https://www.mindstick.com/forum/161912/explain-the-python-strings)


---

Original Source: https://www.mindstick.com/forum/161913/what-is-f-strings-in-python

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
