October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Use Default, Keyword-Only, and Positional-Only Arguments in Python

Understand Python function parameter kinds, use defaults safely, and choose between positional-only and keyword-only arguments for clear, stable APIs.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Python function parameters can be positional-only, positional-or-keyword, or keyword-only; a parameter can also have a default value that makes it optional in a call. Use / to mark positional-only parameters and * to begin keyword-only parameters. These rules let you make calls clearer and keep an API’s public interface stable.

How the three parameter kinds work

Without a separator, an ordinary parameter is positional-or-keyword: callers can pass its value by position or with its name. A default value lets a caller omit that parameter. The slash and asterisk in a function definition change how callers may provide parameters.

def render(item, /, format="text", *, strict=False):
    ...
  • item is positional-only because it appears before /.
  • format is positional-or-keyword and defaults to "text".
  • strict is keyword-only because it follows *, and defaults to False.

The / and bare * are markers, not parameters you pass when calling the function. Python supports the slash syntax in function definitions from version 3.8 onward. See the Python 3.12 language reference.

What does / mean in a Python function definition?

Every parameter before / is positional-only. A caller must supply its value by position, not by parameter name.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
def describe(value, /):
    return str(value)

describe("report")       # valid
describe(value="report") # TypeError

This is useful when the parameter’s name should not be part of the calling interface, or when you want to retain the freedom to rename it later. It can also let a function accept a keyword with the same name through **kwargs:

def foo(name, /, **kwds):
    return name, kwds

foo("positional", name="keyword")

Here, name is bound positionally, while name="keyword" is collected in kwds. Without /, foo(1, name=2) would try to assign the same parameter twice.

What does * mean in a Python function definition?

A bare * ends the positional-or-keyword section and makes every following parameter keyword-only. You must pass those parameters by name:

def save(path, *, overwrite=False):
    ...

save("notes.txt", overwrite=True) # valid
save("notes.txt", True)           # TypeError

A keyword-only parameter does not need a default. Without one, it is required:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
def connect(host, *, timeout):
    ...

connect("example.com", timeout=10) # valid
connect("example.com")              # TypeError

Parameters after a variadic positional parameter such as *args are keyword-only as well. The Python tutorial’s section on special parameters describes both forms.

How defaults make arguments optional

Write parameter=value in the definition to provide a default. Python uses that value only if the caller omits the parameter; an explicitly supplied value takes precedence.

def greet(name, greeting="Hello"):
    return f"{greeting}, {name}!"

greet("Mina")                  # uses "Hello"
greet("Mina", "Welcome")      # supplies greeting by position
greet("Mina", greeting="Hi")  # supplies greeting by name

Defaults are evaluated once when the function is defined, so a mutable default such as a list is reused across calls. To create a fresh list for each call, use None as a sentinel and construct the list inside the function:

def append_item(item, items=None):
    if items is None:
        items = []
    items.append(item)
    return items

This avoids unintentionally sharing one list between calls. The pattern is also shown in the official Python tutorial.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How to choose parameter kinds

Kind Use it when Effect on callers
Positional-only (/) The name has no useful public meaning, the position is the intended convention, arbitrary keywords must remain available, or you may want to rename the parameter without breaking callers. Callers must provide the value by position and cannot rely on the parameter name.
Positional-or-keyword (ordinary parameter) Either calling style is reasonable and you want to allow both. Callers may provide the value by position or by name.
Keyword-only (*) A descriptive name improves readability, or a positional value would be hard to interpret. Callers must use the parameter name; a default determines whether it may be omitted.

For example, a format option may be understandable as a keyword, while a flag such as strict is easier to read when written explicitly as strict=True. Positional-only parameters can insulate callers from parameter renames; as the Python Software Foundation’s tutorial puts it, “For an API, use positional-only to prevent breaking API changes if the parameter’s name is modified in the future.”

Diagnosing argument-binding TypeErrors

Python raises TypeError when a call does not match the function signature. Check the call against these rules:

  • Positional-only parameter passed by name: render(item="report") is invalid when item appears before /.
  • Keyword-only parameter passed by position: render("report", "json", True) is invalid when strict follows *.
  • Required parameter omitted: a parameter without a default must be supplied in an allowed way.
  • Unknown keyword: a keyword must match a parameter name unless the function accepts arbitrary keywords with **kwargs.
  • Value supplied twice: do not provide one parameter positionally and again by keyword, or repeat a keyword. For example, render("report", format="json", strict=True, **{"strict": False}) supplies strict twice.

When an error occurs, compare each argument with the signature from left to right: first positional values, then named values, and finally whether any required parameters remain unbound.

Inspecting a callable’s parameter kinds

For documentation, decorators, or other tools that need to examine a callable, Python’s inspect.signature() returns a Signature object. Its ordered parameters mapping identifies kinds such as POSITIONAL_ONLY, POSITIONAL_OR_KEYWORD, VAR_POSITIONAL, KEYWORD_ONLY, and VAR_KEYWORD. See the Python 3.12 inspect documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import inspect

sig = inspect.signature(render)
for parameter in sig.parameters.values():
    print(parameter.name, parameter.kind, parameter.default)

Check Python compatibility

Positional-only syntax using / requires Python 3.8 or later. If your project supports older interpreters, do not put that syntax in code that must run on them. The tutorial linked above documents Python 3.14.8; the language reference and inspect documentation linked here are for Python 3.12.15.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.