October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan 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 Define and Call Functions in Python

A practical guide to defining Python functions, calling them with arguments, and understanding parameters, return values, defaults, and argument styles.

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.

Define a function with def, a name, parentheses, a colon, and an indented body. Call it by writing its name followed by parentheses containing any required argument values. A function definition makes reusable code available; a call runs that code.

Define a function with def

In Python 3.14.8, the official tutorial explains that the keyword def introduces a function definition. The function name is followed by parentheses around its parameter list, a colon, and an indented body. The definition creates a function object and binds it to that name.

def greet(name):
    """Return a greeting for one person."""
    return f"Hello, {name}!"

Here, greet is the function name and name is a parameter: a name the function uses for an input. Indentation is part of Python syntax, so the body must be indented beneath the def line. The string in triple quotes is a docstring that describes the function.

Call the function and use its result

To run the function, write its name with parentheses and supply a value for its parameter. That value is an argument.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
message = greet("Ada")
print(message)

The call greet("Ada") runs the body with name set to "Ada". The function returns "Hello, Ada!", which the assignment stores in message; print then displays it. Defining a function does not run its body—the call does.

Parameters and arguments

Parameters are the names in a function definition; arguments are the actual values passed when calling it. In def greet(name):, name is a parameter. In greet("Ada"), "Ada" is an argument. This distinction follows the Python Programming FAQ for Python 3.14.8.

Return a value instead of only printing

A return statement ends the function and makes its expression’s value available to the caller. Returning lets calling code store, inspect, or use that value. Printing displays text, but does not by itself provide that text as the function’s result. If a function reaches its end without a return, or uses a bare return, its result is None.

Choose how to pass arguments

Python supports positional and keyword arguments. Positional arguments are matched by order; keyword arguments identify the parameter by name. Use the form that makes a call clear, and follow the function’s signature.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Calling form Example How it works
Positional power(2, 3) Values match parameters by their position.
Keyword power(base=2, exponent=3) Values match the named parameters; their order can differ from the definition.

A keyword must match a parameter name accepted by the function. Do not supply the same parameter more than once—for example, once positionally and again by keyword.

Use defaults for optional inputs

A default value lets a caller omit an argument when there is a sensible standard value.

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

first = greet("Ada")
second = greet("Ada", punctuation="?")

In this example, the first call uses the default punctuation, while the second overrides it. Python evaluates default expressions once, when it defines the function—not afresh on each call. This matters for mutable values such as lists: changes can persist between calls. When each call needs its own list, use None as the default and create a new list inside the function.

Accept a flexible number of arguments

Use *args to collect extra positional arguments into a tuple, or **kwargs to collect extra keyword arguments into a dictionary. In a call, the same operators can unpack an iterable or mapping into arguments.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
def show_values(*args, **kwargs):
    print(args)
    print(kwargs)

items = (10, 20)
options = {"unit": "°C"}
show_values(*items, **options)

The call unpacks items into positional arguments and options into keyword arguments. These flexible forms are useful when a function genuinely needs to forward or accept a variable set of values; ordinary named parameters are clearer for a fixed, small set.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Make the intended calling style explicit

Python signatures can restrict whether callers pass a parameter positionally or by keyword. A slash marks parameters before it as positional-only; a bare asterisk marks parameters after it as keyword-only.

def convert(value, /, *, unit):
    return f"{value} {unit}"

convert(12, unit="kg")

Here, value must be supplied positionally, while unit must be supplied by keyword. Use these markers when the intended calling convention should be explicit; otherwise, parameters can generally be supplied positionally or by keyword, subject to the function’s definition.

A practical way to start

  1. Write a small definition: choose a descriptive name, list the inputs it needs, add a colon, and indent the body.
  2. Decide what the caller needs back: use return for a value that other code should use; use print only when displaying text is the goal.
  3. Call it with a concrete value: match each required parameter with an argument, positionally or by keyword.
  4. Check the result: store or print the return value so you can see what the function produces.

For a free, structured reference, see the Python 3.14.8 tutorial section on defining functions. The Python 3.14.8 Programming FAQ explains the parameter-and-argument distinction. For precise syntax details, consult the Python 3.14.7 language reference.

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

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.