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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Python has no special void declaration. Define a function with def, indent its body, and leave out a value-returning return. When the function reaches the end, Python returns None. A bare return also returns None, but exits immediately.

That means a function can print a message, modify state, or perform another action while its call still evaluates to None. The distinction between an observable side effect and a returned value is the key to writing and calling a void-style function correctly.

What a “void function” means in Python

In languages such as C, C++, or Java, a function can be declared with a void return type. Python uses a different model: every function call has a result, and a function that does not return another value produces the singleton object None. “Void function” is therefore an informal description for a function whose caller is not expected to use a meaningful returned value.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

The official Python tutorial states: “return without an expression argument returns None. Falling off the end of a function also returns None.” You can read that explanation in the Python tutorial’s control-flow chapter. The CPython tutorial source shows the same behavior.

#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter | 4Pack Type C Female to A Male Cable Converter for Apple Duo 17 16 15 14 Plus,iWatch Watch 12 11 10,iPad 9 8 Air,Airpods 5 4
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

You do not write void before the function name, and you do not need a special keyword to make a function “void.” The function definition, its indented body, and its control flow determine what happens.

The smallest working example

def greet(name):
    print(f'Hello, {name}!')

greet('Ada')

The def keyword starts the definition. greet is the function name, name is a parameter, and the colon ends the header. The indented print statement is the body. Calling greet('Ada') prints Hello, Ada!. Because the body has no value-returning return, the call result is None.

The printed greeting is output produced by a side effect. It is not the function’s return value. This distinction matters whenever another expression, assignment, or caller uses the result of the call.

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.

What happens when the call is evaluated

A function definition stores the instructions; the call runs them. In the example above, Python evaluates the argument 'Ada', enters greet, executes print, and then reaches the end of the body. At that point the call expression has the value None. The visible line and the call result are produced by the same invocation, but they are different channels of communication.

You can ignore the result when the action is all you need:

greet('Ada')

You can also make the result visible for learning or debugging:

result = greet('Ada')
print(result)

The first statement prints the greeting. The assignment stores None in result, and the second statement prints that object. Assigning the result does not suppress the function’s side effect; it merely gives the call result a name.

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

How to create a void-style function step by step

  1. Choose an action. Decide what the function should do, such as display a message or perform a procedure whose useful outcome is the action itself.
  2. Write the header. Start with def, add a descriptive name, place parameters in parentheses, and finish with a colon: def announce(message):.
  3. Indent the body. Put the statements that perform the action on the following indented lines. Consistent indentation is what makes those statements part of the function.
  4. Document the purpose when useful. An optional first string expression in the body is a docstring. It should explain the action or any important expectations for callers.
  5. Choose the control flow. Omit return when the function should continue through the body and finish normally. Use a bare return when a condition should stop the function before the remaining statements run.
  6. Call the function. Write its name followed by parentheses and provide arguments for its parameters, for example announce('Done').
  7. Check the result only if needed. The call may be assigned to a variable or passed to print; in either case, a function with no value-returning return produces None.

Omitting return versus using a bare return

Both forms produce None. The difference is when execution stops.

Form Control flow Call result Use it when
No return Statements run until the body reaches its end None The action should complete normally
Bare return Execution exits immediately at that line None A condition requires an early exit
return expression Execution exits and supplies the expression’s value The expression’s value The caller needs data; this is no longer void-style behavior

For a function that should always run to completion, leaving out return communicates the straightforward control flow. For a function with a guard condition, a bare return prevents later statements from running while preserving the same no-useful-value contract.

Normal completion

def announce(message):
    print(message)

result = announce('Done')
print(result)

The first call prints Done. The second print displays None, because that is what was assigned to result. The text printed by the function and the value assigned to result are two separate outcomes.

Early completion

def announce_if_present(message):
    if message is None:
        return
    print(message)

When message is None, the bare return ends the function before it reaches print. When a non-None message is supplied, the function prints it and then falls off the end, again producing None.

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

Keeping every branch consistent

A void-style contract is easiest to understand when all normal paths return no useful value. In announce_if_present, the guard path uses a bare return, while the other path reaches the end. Both paths therefore produce None; they differ only in whether the message is printed.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter | USB C Dongle with 90W Max Power Delivery, 3×5Gbps USB A Data Ports, for MacBook, Dell, and More (Charger Not Included)
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

When reviewing a function, inspect each conditional branch separately. A branch that reaches the end implicitly returns None. A branch with a bare return also returns None. If one branch contains return expression, the function now has a mixed contract: some calls provide data and others provide None. That may be intentional, but it is no longer a purely void-style design and should be clear to callers.

Likewise, a bare return placed before an action makes that action conditional. Move it only when the desired execution order is clear: statements above it run, statements below it do not.

Printing is not returning

A frequent mistake is assuming that visible output is automatically a return value. Consider:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
def show_fibonacci(numbers):
    for number in numbers:
        print(number)

value = show_fibonacci([0, 1, 1, 2, 3])
print(value)

The function writes each number to output, then value is None. If a caller needs to use the sequence later, the function must return a value instead:

def make_fibonacci(numbers):
    return numbers

series = make_fibonacci([0, 1, 1, 2, 3])
print(series)

These functions have different contracts. The first performs printing as its purpose. The second supplies data to its caller. Changing print(numbers) to return numbers is not a cosmetic edit; it changes how callers are expected to use the function.

The same rule applies to a formatted message. This function displays text:

def announce(message):
    print(message)

This one makes text available to the caller:

def format_message(message):
    return f'Message: {message}'

Choose the first when the display itself is the intended outcome. Choose the second when another statement must store, compare, or display the resulting text later.

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

How to observe the implicit None result

You normally call a void-style function for its action and ignore the result:

greet('Ada')

If you need to verify what it returns, assign the call or nest it inside another print:

result = greet('Ada')
print(result)

print(greet('Ada'))

The first form prints the greeting during the call and then prints None from result. The second form also prints the greeting first, followed by None from the outer print. The order is a useful diagnostic: output from inside the function occurs before the caller displays the call’s result.

When a branch may return early, checking whether the result is None can help you understand the control flow. It does not turn the function into a value-producing function; it simply makes the implicit result visible.

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

Do not confuse the displayed word None with the string 'None'. The former is Python’s singleton object and is what an omitted or bare return produces. A quoted word would be ordinary text and would require an explicit return 'None' to become the call result.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter | 85W Max PD, 2 USB 3.0 & 1 USBC Data Ports, SD/TF Card Reader, for Laptops/Mac and Other Type C Devices (Charger Not Included)
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Adding a docstring

A docstring is an optional first string expression in a function body. It documents what the function does for readers and tools that inspect the function. A void-style function can use one without changing its return behavior.

def greet(name):
    '''Print a greeting for name without returning a message.'''
    print(f'Hello, {name}!')

The triple-quoted string is documentation, not a value returned to the caller. Since it is the first statement in the body, Python treats it as the function’s docstring; execution still reaches the print statement and then falls off the end with a result of None.

A useful docstring states the action rather than promising a value. Wording such as “Prints a greeting” sets the expectation that callers invoke the function for its side effect. Wording such as “Returns a greeting” would suggest a different implementation and contract.

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

Designing the function’s contract

Before writing the body, decide whether the caller needs a result. A void-style function is appropriate when the useful outcome is an action, such as displaying a status message. It is also suitable when the function’s job is a procedure and the caller does not need data from that procedure.

  • Use a void-style function when the caller should trigger an action and there is no meaningful value to consume.
  • Return a value when another part of the program must calculate with, store, compare, or display data produced by the function.
  • Do not use printing as a substitute for returning. Output is sent to the display; it is not available to the caller as the call result.
  • Use a bare return for control flow. It communicates that a branch should stop now, not that a value should be supplied.

For example, a function named announce naturally performs communication, while a function named format_message suggests that the caller should receive text. Names do not enforce behavior, but a name that matches the contract makes the code easier to call correctly.

Keep the action and the contract aligned. If callers repeatedly need to capture what a function printed, that is a sign the operation may belong in a value-returning function instead. Conversely, returning a value that callers consistently ignore can make the interface less clear than a procedure whose purpose is explicitly the side effect.

Common mistakes and their fixes

Writing a nonexistent void declaration

Code such as void greet(name): is not Python function syntax. Start with def and put the colon after the parameter list:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
def greet(name):
    print(f'Hello, {name}!')

Forgetting the colon or indentation

The function header requires a trailing colon. Its body must be indented beneath the header. If the indentation is missing or inconsistent, Python cannot identify the function body correctly.

Returning the printed text by accident

This function prints the message but still returns None:

def announce(message):
    print(message)

If the caller needs the text, write return message instead of only printing it. That is a deliberate change from an action-only function to a value-returning function.

Adding an unnecessary bare return at the end

These definitions have the same result:

def first():
    print('Done')

def second():
    print('Done')
    return

In first, execution falls off the end. In second, the bare return exits after printing. At the final line, the explicit statement adds no new result; use it only when its control-flow meaning is helpful.

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

Confusing a returned None with no function call

A function can run successfully, produce output, and still return None. Seeing None in a variable does not by itself mean the function failed. Check whether the intended side effect occurred and whether the function was called in the expected branch.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray | Data transfer & Fast charging for MacBook, iPhone 17/16/15, iPad, Samsung Galaxy, Apple Watch
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Expecting print to compose like a value

A print-only call is not a replacement for a returned expression. If a later operation needs text, keep that text as data with return; printing it first does not make it available for another call. Separate the function that creates or formats data from the function that displays it when both responsibilities are needed.

Hiding an early exit

A bare return is useful, but placing it inside a condition that readers cannot easily see can make the action appear unreliable. Keep guard conditions close to the top of the function and document the action so it is apparent which inputs cause the function to stop before printing.

Examples of useful void-style patterns

Status notification

def report_status(status):
    '''Print the current status.'''
    print(f'Status: {status}')

report_status('Ready')

The caller invokes the function for its notification. There is no message value to store, so the implicit None result is appropriate.

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

Guard clause before an action

def print_name(name):
    if not name:
        return
    print(name)

The bare return handles the branch in which there is no name to print. A valid name reaches the print statement, and both paths return None.

Several actions in sequence

def prepare_and_report(item):
    print(f'Preparing {item}')
    print(f'{item} is ready')

Both statements run in order when the function is called. The function’s useful effect is the two messages, not a value returned to the caller.

Action with an optional early stop

def report_if_ready(status):
    if status is None:
        return
    print(f'Status: {status}')
    print('Report complete')

The guard prevents both messages when there is no status. For any supplied status, the statements run in order and the function reaches the end. Each path still has the same None result, which keeps the caller’s expectations simple.

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

A practical test checklist

Use this short checklist when checking a new void-style function:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Confirm the definition begins with def, has a valid name and parameter list, and ends its header with a colon.
  2. Confirm every statement intended to belong to the function is indented in the body.
  3. Call the function with the required arguments.
  4. Observe the intended side effect, such as the expected printed text.
  5. If the result matters for debugging, assign the call to a variable or wrap the call in print and verify that the displayed result is None.
  6. Inspect every branch: a missing value-returning return means that branch also produces None.
  7. Check the order around each bare return to ensure statements after it are intentionally skipped.
  8. Replace a print-only implementation with return expression only when callers genuinely need that expression as data.

Frequently asked questions

Does Python have a void keyword?

No. Use def to define the function and omit a value-returning return statement. “Void” describes the intended use, while Python represents the result as None.

What does a function return if it has no return statement?

When execution reaches the end of the function, the call returns None. This is implicit; no extra statement is required.

Is return the same as return None?

A bare return returns None and exits immediately. Writing return None also supplies None and exits, but the bare form is the concise way to express an early stop without a value.

Should a void-style function use a bare return at the end?

Usually not. Reaching the end already returns None. Add a bare return at the end only if making the exit explicit helps communicate control flow; use it before the end when an early branch must stop.

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

Why does print(greet('Ada')) show both a greeting and None?

The inner call prints the greeting as its side effect. The outer print then prints the call’s result, which is None. Printing and returning are separate operations.

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display | 85W Max PD, 1 Powered USB-C 5Gbps & 2 Powered USB-A 3.0 5Gbps Data Ports, for MacBook Pro, MacBook Air, Dell and More (Black)
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

How do I make the function return the message instead?

Replace the print-only behavior with a value-returning statement, such as return message or return f'Hello, {name}!'. The caller can then assign or print that returned value.

Can a function print something and still be void-style?

Yes. Printing is a side effect, and the function remains void-style as long as it does not return a useful expression. Its call result is still None.

Does a docstring change the return value?

No. A string used as the first statement is the function’s docstring. It documents the function; after the remaining body runs, the function still returns None if no value is returned.

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

What if one branch returns a value and another branch does not?

The value-returning branch supplies its expression, while the branch that falls through or uses a bare return produces None. That mixed contract can be valid, but it is not a consistently void-style function and callers must account for both outcomes.

Official references

The Python tutorial’s control-flow documentation covers function definitions, docstrings, bare return, implicit None, and the difference between printing a Fibonacci series and returning a list: docs.python.org tutorial. The corresponding tutorial source is available in CPython’s repository. The documentation landing page currently identifies itself as Python 3.15.0 documentation: Python documentation. Check the version shown on the official site when you need release-specific wording.

Frequently Asked Questions

What is a void function in Python?

It is an informal term for a function called for its action rather than a useful returned value. Python has no void declaration; such a function returns None when it finishes.

How do I create one?

Write a normal function with def, a parameter list, a colon, and an indented body. Omit a value-returning return statement.

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

What is the difference between omitting return and using bare return?

Omitting return lets the body run to its end. A bare return stops execution immediately. Both produce None.

Does print return the text it displays?

No. print produces output, while the surrounding function still returns None unless it explicitly returns a value.

When should I return a value instead?

Return a value when another part of the program must store, compare, calculate with, or display data produced by the function.

The Bottom Line

Define a Python void-style function with def and an indented body, then omit a value-returning return. Reaching the end or using a bare return gives the caller None; printing remains a separate side effect.

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.

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.