Currying in Python — ELI5

Imagine ordering a sandwich.

At most sandwich shops, you tell them everything at once: bread, meat, toppings, sauce. But what if there was a shop where you could say “wheat bread” today, and it gave you a card. Tomorrow you hand in that card and say “turkey.” The next day you add “lettuce.” Each time, the shop remembers what you already picked.

That’s currying.

In Python, a normal function wants all its ingredients at once. A curried function lets you give ingredients one at a time. Each time you give one, it remembers it and waits for the next.

Why would you do this?

  • You can set up part of a job now and finish it later.
  • You can reuse the half-done version for different endings.
  • It keeps your code flexible without extra work.

Example: you have a function that adds two numbers. Normally you say “add 3 and 5.” With currying, you say “add 3” and get back a new function that’s waiting for the second number. Give it 5 later, and you get 8. Give it 10, and you get 13. Same starter, different results.

One Thing to Remember

Currying is giving a function its inputs one at a time, getting a new specialized function back at each step until all inputs are filled in.

pythonfunctional-programmingcurrying

See Also

  • Python Function Composition Discover how snapping small Python functions together creates powerful new ones — like building words from letters.
  • Python Functional Pipelines See how chaining small Python functions into a pipeline turns messy data work into a clean assembly line.
  • Python Monads In Python Understand monads through a simple lunchbox analogy — no math degree required, just curiosity.
  • Ci Cd Why big apps can ship updates every day without turning your phone into a glitchy mess — CI/CD is the behind-the-scenes quality gate and delivery truck.
  • Containerization Why does software that works on your computer break on everyone else's? Containers fix that — and they're why Netflix can deploy 100 updates a day without the site going down.