Positional-Only Parameters in Python — ELI5

Think about a vending machine. You put coins in the slot and press a button for your snack. You don’t write a label on each coin saying “this one is for the price.” The machine figures it out by position — coins go in the slot, button gets pressed, snack comes out.

In Python, when you call a function, you usually have two choices: pass values by position (just put them in order) or by name (say which argument gets which value). Most of the time, both work fine.

But sometimes, a function designer says: “These first few arguments should only be passed by position. Don’t use their names.” That’s a positional-only parameter.

Why would anyone want that? Imagine a function called distance(x, y). The names x and y are just internal labels — the function author might want to rename them to a and b later without breaking everyone’s code. If people were writing distance(x=5, y=10), changing the name would break their programs. But if the arguments are positional-only, people write distance(5, 10), and renaming is safe.

Python uses a forward slash / in the function definition to mark this boundary. Everything before the / is positional-only. It looks a little weird at first, but it’s just the language’s way of saying “don’t use names for these.”

Many built-in Python functions have always worked this way — len(), range(), print() — you’ve been using positional-only parameters without even knowing it.

The one thing to remember: Positional-only parameters are arguments you pass by position, not by name — giving the function author freedom to change internal names without breaking your code.

pythonfundamentalspython38

See Also

  • Python 310 New Features Python 3.10 gave programmers a shape-sorting machine, friendlier error messages, and cleaner ways to say 'this or that' in type hints.
  • Python 311 New Features Python 3.11 made everything faster, error messages smarter, and let you catch several mistakes at once instead of stopping at the first one.
  • Python 312 New Features Python 3.12 made type hints shorter, f-strings more powerful, and started preparing Python's engine for a world without the GIL.
  • Python 313 New Features Python 3.13 finally lets multiple tasks run at the same time for real, added a speed booster engine, and gave the interactive prompt a colourful makeover.
  • Python Exception Groups Python's ExceptionGroup is like getting one report card that lists every mistake at once instead of stopping at the first one.