# Monkey Patching

say it: **“MUNG-kee PACH-ing”** **/ˈmʌŋki ˈpætʃɪŋ/**

Replacing a function or method while the program runs.

## What is **monkey patching**?

**Monkey patching** means replacing a function or method while the program is running. It's handy in tests, but risky in real code because it changes behavior far from where you'd look.

```python
import random

random.randint = lambda low, high: 6   # every dice roll is now 6
print(random.randint(1, 6))           # 6: fine in a test, confusing anywhere else
```

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

Updated: November 17, 2026

Source: https://www.ask-codey.com/glossary/monkey-patching
