# \_\_str\_\_ and \_\_repr\_\_

*noun*

say it: **“DUN-der STUR and DUN-der REP-er”** **/ˈdʌndər ˈstɝ ənd ˈdʌndər ˈrɛpər/**

Two methods a class can write: \_\_str\_\_ sets how an object looks when printed for users, and \_\_repr\_\_ the more detailed text developers see while debugging.

## What do `__str__` and `__repr__` do?

`__str__` sets what an object looks like when printed for users. `__repr__` sets the more detailed version developers see while debugging.

```python
class Product:
    def __init__(self, name, price):
        self.name, self.price = name, price

    def __str__(self):
        return f"{self.name} (${self.price})"

print(Product("Lamp", 25))  # Lamp ($25)
```

## In a sentence

- “The debugger shows each product through its **\_\_repr\_\_** method.”
- “With **\_\_str\_\_**, print(lamp) shows Lamp ($25) instead of a memory address.”

Level: Journeyman · [More Python terms at this level](https://www.ask-codey.com/glossary?category=python&level=3)

Updated: November 19, 2026

Source: https://www.ask-codey.com/glossary/str-and-repr
