---
title: "f-strings"
space: "Student Handbook"
url: "https://portal.cs17.org/student-handbook/python-manual/strings/f-strings"
updated: "2026-10-05"
---

Puts values into text.

## Synopsis

```python
f"text {value} more text"
f"{number:.2f}"
f"{number:,}"
```

## Description

Put `f` before the opening quote. Python replaces each `{ }` with the value of what is inside, converting it to text for you.

After a colon you can say how to show a number: `.2f` means 2 decimal places, and `,` adds commas.

## Parameters

| Name | Meaning |
| --- | --- |
| `{ }` | Any variable or expression, such as `{name}` or `{x + y}`. |

## Return value

A `str`.

## Example

```python
name = "David"
x = 3
print(f"hello, {name}")
print(f"{x} squared is {x * x}")
print(f"{3.14159:.2f}")
print(f"{1000000:,}")
```

It prints:

```text
hello, David
3 squared is 9
3.14
1,000,000
```

## Common mistake

```python
name = "David"
print("hello, {name}")
```

It prints:

```text
hello, {name}
```

Without the `f`, the braces are printed as they are.

## See also

[print](/student-handbook/python-manual/built-in-functions/print), [str](/student-handbook/python-manual/built-in-functions/str), [round](/student-handbook/python-manual/built-in-functions/round)

[f-strings in the Python documentation](https://docs.python.org/3/tutorial/inputoutput.html#formatted-string-literals)
