When I build a small Python automation script, I often need functions that simply do something. They may write a log entry, save a report, display a status message, or send an email. The function acts, but the next line of code does not need a value back.
That is where developers often search for a “void function in Python,” especially when they come from languages such as Java, C#, or C++. Python handles this idea differently, but the pattern is simple once you understand it.
You will learn how to create a void function in Python, how Python uses None, when to add return type hints, and how to use these functions in a practical report-processing script.
What Is a Void Function in Python?
A void function is a function that acts without returning a useful result to the caller. In some programming languages, developers use the void keyword to mark these functions.
Python does not have a void keyword. Instead, a Python function returns None automatically when it reaches the end without a return statement that provides a value.
For example, this function displays a message:
def show_report_status():
print("Monthly report created successfully.")
When you call the function, it prints the message:
show_report_status()
Output:
Monthly report created successfully.
I executed the above example code and added the screenshot below.

The function completes its task, but it does not send a calculated value back. That makes it a Python version of a void function.
A function is a named block of reusable code. If you need a refresher on function syntax, see this guide on how to define a function in Python.
How to Create a Void Function in Python
To create a void function in Python, define a function with def, add the statements it should run, and leave out a value-returning return statement.
Here is the basic structure:
def function_name():
# Perform an action here
print("Task completed")
Python automatically returns None after it finishes the function body.
Create a simple void function
Suppose you run a local Python script that prepares a daily sales report. You want a reusable function that prints a clear heading before the script starts processing data.
def print_report_header():
print("=" * 40)
print("DAILY SALES REPORT")
print("=" * 40)
Call it like this:
print_report_header()
Output:
========================================
DAILY SALES REPORT
========================================
I executed the above example code and added the screenshot below.

This function does not calculate anything or return a result. It only prints output, which makes it a good example of a void function.
A function name should describe the action it performs. In this case, print_report_header() tells you exactly what happens when you call it. Follow Python naming conventions for variables to keep your script readable as it grows.
Confirm that the function returns None
You can store the result of a void function call in a variable. Python will store None.
def save_report_message():
print("Report saved.")
result = save_report_message()
print(result)
Output:
Report saved.
None
The print("Report saved.") line runs first. Then Python assigns None to result because save_report_message() does not return a value.
This behavior matters because many beginners accidentally expect a value after calling a function that only prints something.
def display_total():
print(250)
total = display_total()
print(total + 10)
This code raises an error because total holds None, not 250. If you want to reuse the number later, return it instead of only printing it. Learn more about using return in this detailed guide to the Python return statement.
Create a Void Function in Python With Parameters
Most real-world void functions need information from the caller. You pass that information through parameters, which are variables listed inside the function definition.
Here is a function that logs the name of each processed report file:
def log_processed_file(file_name):
print(f"Processed file: {file_name}")
Call it with different file names:
log_processed_file("sales_january.csv")
log_processed_file("sales_february.csv")Output:
Processed file: sales_january.csv
Processed file: sales_february.csv
I executed the above example code and added the screenshot below.

The function still does not return a result. It uses the provided file_name value to perform its action.
If you want to work with input values in more detail, see how to use the input function in Python and how to use Python functions with optional arguments.
Use multiple parameters
A report automation script may need to log both a file name and a row count.
def log_import_summary(file_name, row_count):
print(f"Imported {row_count} rows from {file_name}.")
Now call the function:
log_import_summary("sales_march.csv", 1284)Output:
Imported 1284 rows from sales_march.csv.
This design keeps your main script clean. Instead of repeating the same print format everywhere, you put that logic in one function.
Pro Tip: In my experience, void functions work best when each one handles one clear action. A function named
process_report()should not print headers, validate data, write files, and send emails all at once. Split those tasks into smaller functions so errors are easier to find.
Use -> None for a Python Void Function
Python supports type hints, which are optional labels that show the expected type of a variable, parameter, or returned value. They do not change how standard Python code runs, but they help readers, editors, and code-checking tools understand your intent.
Use -> None to make it clear that a function does not return a useful value.
def log_message(message: str) -> None:
print(f"[LOG] {message}")
Call the function:
log_message("Starting report import")
log_message("Checking for missing columns")
log_message("Report import complete")Output:
[LOG] Starting report import
[LOG] Checking for missing columns
[LOG] Report import complete
The message: str hint says that message should contain text. The -> None hint says the function performs an action and returns no useful result.
You do not need to install a module to use basic type hints. They work in modern Python versions, including Python 3.10 and later.
Why -> None helps in real scripts
Consider these two function definitions:
def create_backup(file_name):
print(f"Creating backup for {file_name}")
def create_backup(file_name: str) -> None:
print(f"Creating backup for {file_name}")
Both functions run the same way. The second version communicates more information:
file_nameshould be text.- The function performs an action.
- The caller should not expect a return value.
This becomes especially useful in larger automation projects with many functions. A teammate can see the function contract without opening every line of code.
Build a Practical Void Function Example
Let’s build a small report-processing example. Imagine that a Python script reads a CSV file, checks each record, and writes progress messages to a text log.
A void function is a strong fit for the logging task because the script does not need a result after it writes each line.
from datetime import datetime
def write_log(message: str) -> None:
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
with open("report_processing.log", "a", encoding="utf-8") as log_file:
log_file.write(f"{timestamp} - {message}\n")
This function does three things:
- It gets the current date and time.
- It opens
report_processing.login append mode using"a". - It writes the message as a new line in the file.
The with open(...) statement closes the file automatically after Python finishes writing. That prevents file-handle problems in long-running automation scripts.
Now use the function in a report workflow:
def process_report(file_name: str) -> None:
write_log(f"Started processing {file_name}")
print(f"Reading {file_name}...")
print("Validating report columns...")
print("Creating summary...")
write_log(f"Finished processing {file_name}")
print("Report processing complete.")
Call it:
process_report("sales_april.csv")This main function also uses -> None because it coordinates actions rather than returning data. If you need to create files during your workflow, this guide explains how to create a file in Python if it does not exist.
Add error handling to a void function
A try-except block lets you handle an exception, which is an error that interrupts normal program flow. File operations often fail because of missing folders, permissions, or locked files.
Here is a safer logging function:
from datetime import datetime
def write_log(message: str) -> None:
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
try:
with open("report_processing.log", "a", encoding="utf-8") as log_file:
log_file.write(f"{timestamp} - {message}\n")
except OSError as error:
print(f"Could not write to the log file: {error}")
This function still returns None. It handles a failure locally, displays a useful message, and lets the rest of the script continue if that makes sense for your use case.
For scripts that handle different failure types, learn how to catch multiple exceptions in Python.
Void Function vs Return Function in Python
Use a void function when you need an action. Use a return function when later code needs the result.
| Situation | Void function | Return function |
|---|---|---|
| Print a progress message | Yes | No |
| Write a line to a log file | Yes | No |
| Save an exported report | Yes | No |
| Calculate report total | No | Yes |
| Validate whether a file exists | Usually no | Yes |
| Convert raw text into a number | No | Yes |
Here is a return function that calculates a total:
def calculate_total(values: list[float]) -> float:
return sum(values)
You can reuse its value:
sales_total = calculate_total([120.50, 89.99, 210.00])
print(f"Total sales: {sales_total}")
Output:
Total sales: 420.49
By contrast, this function only displays the total:
def print_total(values: list[float]) -> None:
print(f"Total sales: {sum(values)}")
Use it like this:
print_total([120.50, 89.99, 210.00])
Choose calculate_total() when another function, an Excel export, or an API request needs the number. Choose print_total() when you only want to show the result to a person running the script.
You can also return multiple values from a function in Python when a function needs to provide more than one result.
Should You Write return None Explicitly?
You can write return None in a Python void function, but you usually do not need it.
def show_completion_message() -> None:
print("Processing complete.")
return None
This function works, but Python already returns None when it reaches the end. Most developers leave it out:
def show_completion_message() -> None:
print("Processing complete.")
Use an explicit return None when it makes a complex code path easier to read.
def send_report_if_ready(is_ready: bool) -> None:
if not is_ready:
print("Report is not ready.")
return None
print("Sending report.")
The explicit return stops the function early when the report is not ready. In this situation, it communicates intent clearly.
For more control over function flow, see how to exit a function in Python.
Things to Keep in Mind
- Do not expect a result: A void function returns
None, so do not store its result and use it as text, a number, or a list. - Use
-> Nonefor clarity: Add a return type hint to production scripts when the function exists only to perform an action. - Keep one responsibility: Let a void function handle one task, such as logging, printing, saving, or sending a notification.
- Handle expected errors: Add exception handling around file access, API requests, and other operations that can fail.
- Use meaningful action names: Start names with verbs such as
print_,write_,save_,send_, orupdate_. - Avoid hidden global changes: Pass values into the function instead of changing global variables whenever possible. Learn how to access variables outside a function in Python before relying on global state.
Frequently Asked Questions
Does Python have a void function?
Python does not use a void keyword. A function acts like a void function when it completes without returning a value, because Python returns None automatically.
How do I make a function return nothing in Python?
Define the function and do not use return with a value. You can also use -> None as a type hint to show that the function performs an action only.def greet() -> None:
print("Hello")
What does None mean in a Python function?
None is Python’s special value for “no value” or “nothing here.” Functions return None automatically when they do not return another value.
Should I use return None in Python?
Usually, no. Python adds None automatically at the end of a function. Use return None when you need to leave a function early or want to make a branch explicit.
Can a void function take arguments in Python?
Yes. A void function can accept one or more parameters, use them to perform an action, and still return None.def print_name(name: str) -> None:
print(name)
Can a Python function print and return a value?
Yes, but use that approach carefully. Printing handles display, while returning provides data to the calling code. In most production scripts, keep those responsibilities separate so the function stays easier to test and reuse.
A void function in Python is simply a function that performs an action and returns None instead of useful data. Start with small functions that print, log, or save one thing, then combine them into clear automation workflows once the basics work. I hope you found this article helpful.
You May Also Like
- How to call a function in Python
- How to use lambda functions in Python
- How to use default function arguments in Python
- How to call a function within another function in Python
- Difference between functions and methods in Python

Bijay Kumar is an experienced Python and AI professional who enjoys helping developers learn modern technologies through practical tutorials and examples. His expertise includes Python development, Machine Learning, Artificial Intelligence, automation, and data analysis using libraries like Pandas, NumPy, TensorFlow, Matplotlib, SciPy, and Scikit-Learn. At PythonGuides.com, he shares in-depth guides designed for both beginners and experienced developers. More about us.