Use option 1 for simplicity & adherence to spec.

def foo() -> None

Option 1 & 2 are the 'same' as per PEP 484 -- Type Hints, ...

When used in a type hint, the expression None is considered equivalent to type(None).

but the type-hinting specification does not use type(...).

This is why most of the examples use None as return type.

Answer from AKS on Stack Overflow
🌐
Scientech Easy
scientecheasy.com › home › blog › void function in python
Void Function in Python - Scientech Easy
February 28, 2025 - Void function in Python is a function that performs an action but does not return any computed or final value to the caller.
Discussions

Python void return type annotation - Stack Overflow
In python 3.x, it is common to use return type annotation of a function, such as: def foo() -> str: return "bar" What is the correct annotation for the "void" type? I'm More on stackoverflow.com
🌐 stackoverflow.com
why none happens on this "In Python, a void function is a function that does not return any value. When you assign the result of a void function to a variable, you get the special value None. This happens because in Python, when a function does not explicitly return a value, it implicitly returns None. For example, consider the following void function: def greet(): print("Hello!") If you assign the result of this function to a variable: result = greet() The value of result will be None. So, the correct answer to the question is: d. the special value None
On Studocu you find all the lecture notes, summaries and study guides you need to pass your exams with better grades. More on studocu.com
🌐 studocu.com
1
September 3, 2024
python - Is it always a best practice to write a function for anything that needs to repeat twice? - Software Engineering Stack Exchange
These method calls are functions intended to be wrapped in other systems. If you can't find such a system, build it! You obviously can't code like that so you need to step back and look at the problem, what is that repeated code actually doing? It's specifying some strings and their relationship(a tree) and joining the leaves of that tree to actions. So what you really want is to say: class Menu { @MenuItem("File|Load") public void ... More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
January 13, 2015
Python Void Function
Is there a way to define a void function in python? (with no parameters). That isn't what "void" means in any language - void functions (in statically-typed languages where functions declare a return type) return no value. Since all functions in Python return values (that value may be None) there's no such thing as a void function in Python, but also functions in Python don't have to declare a return type. More on reddit.com
🌐 r/learnpython
12
1
February 9, 2021
🌐
Python Guides
pythonguides.com › create-a-void-function-in-python
How To Create A Void Function In Python?
April 23, 2025 - A void function, also known as a non-returning function, is a function that performs a specific operation but does not return any value. Unlike regular functions that typically return a result, void functions are used when you want to execute a block of code without expecting any output.
Top answer
1 of 2
340

Use option 1 for simplicity & adherence to spec.

def foo() -> None

Option 1 & 2 are the 'same' as per PEP 484 -- Type Hints, ...

When used in a type hint, the expression None is considered equivalent to type(None).

but the type-hinting specification does not use type(...).

This is why most of the examples use None as return type.

2 of 2
151

TLDR: The idiomatic equivalent of a void return type annotation is -> None.

def foo() -> None:
    ...

This matches that a function without return or just a bare return evaluates to None.

def void_func():  # unannotated void function
    pass

print(void_func())  # None

Omitting the return type does not mean that there is no return value. As per PEP 484:

For a checked function, the default annotation for arguments and for the return type is Any.

This means the value is considered dynamically typed and statically supports any operation. That is practically the opposite meaning of void.


Type-hinting in Python does not strictly require actual types. For example, annotations may use strings of type names: Union[str, int], Union[str, 'int'], 'Union[str, int]' and various variants are equivalent.

Similarly, the type annotation None is considered to mean "is of NoneType". This can be used in other situations as well as return types, though you will see it most often as a return-type annotation:

bar : None

def foo(baz: None) -> None:
    return None

This also applies to generic types. For example, you can use None in Generator[int, None, None] to indicate a generator does not take or return values.


Even though PEP 484 suggests that None means type(None), you should not use the latter form explicitly. The type-hinting specification does not include any form of type(...). This is technically a runtime expression, and its support is entirely up to the type checker. The mypy project is considering whether to remove support for type(None) and remove it from 484 as well.

Or maybe we should update PEP 484 to not suggest that type(None) is valid as a type, and None is the only correct spelling? There should one -- and preferably only one -- obvious way to do it etc.

--- JukkaL, 18 May 2018

🌐
Study.com
study.com › courses › computer science courses › computer science 113: programming in python
Return & Void Statements in Python - Lesson | Study.com
July 21, 2020 - Since nothing was returned to the variable, Python printed ''None'' to the console. Such functions which do not have a return statement in them are called void functions.
🌐
University of Pittsburgh
sites.pitt.edu › ~naraehan › python2 › user_defined_functions.html
Python 2.7 Tutorial
Python 2.7 Tutorial With Videos by mybringback.com User-Defined Functions Play All on YouTube << Previous Tutorial Next Tutorial >> On this page: def, return, docstrings, help(), value-returning vs. void functions Functions: the Basics Let's bust out some old-school algebra.
🌐
Brainly
brainly.in › computer science › secondary school
Void function in python - Brainly.in
March 13, 2023 - Python, it is possible to compose a function without a return statement. Functions like this are called void, and they return None, Python's special object for "nothing".
Find elsewhere
🌐
Runestone Academy
runestone.academy › ns › books › published › py4e-int › functions › fruitfulvoid.html
5.10. Fruitful functions and void functions — Python for Everybody - Interactive
Some of the functions we are using, such as the math functions, yield results; for lack of a better name, I call them fruitful functions. Other functions, like print_twice, perform an action but don’t return a value. They are called void functions. Q-1: “Fruitful functions” are functions that must… ... Correct! Fruitful functions yield results in the form of a return value.
🌐
Quora
quora.com › What-does-void-mean-in-Python-and-why-does-it-return-none
What does void mean in Python, and why does it return none? - Quora
Answer (1 of 5): void doesn’t mean anything in Python - void isn’t a keyword, or inbuilt function or a package in the standard library. An experienced developer who has used C or C++ might described a particular function as being a ‘void function’, especially if they are being a bit sloppy with ...
🌐
Studocu
studocu.com › st. mary's university (ethiopia) › computer › question
[Solved] why none happens on this In Python a void function is a function - computer (124) - Studocu
September 3, 2024 - why none happens on this "In Python, a void function is a function that does not return any value. When you assign the result of a void function to a variable, you get the special value None.
🌐
EyeHunts
tutorial.eyehunts.com › home › python void function
Python void function
September 8, 2023 - Function foo() returns void,(simplicity returns None as what goo() returns explicitly). Do comment if you have any doubts or suggestions on this Python function topic. ... All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
🌐
Mga
comp.mga.edu › learning › python › module › 8 › topic › 49
8-3. Void Functions and Value Returning Functions
April 22, 2025 - In Python, functions can be categorized into two main types: void functions and value-returning functions. Void functions are designed to perform specific tasks without returning any value to the caller.
🌐
Scribd
scribd.com › document › 842323122 › Void-Functions-and-Functions-with-Return-Values
Void Functions and Functions With Return Values | PDF | Parameter (Computer Programming) | Scope (Computer Science)
The document explains the concepts of void functions and functions with return values in Python, detailing how return statements work and the different types of parameters. It also covers variable scopes, namespaces, and types of arguments, including default, keyword, positional, and arbitrary ...
Top answer
1 of 15
202

Although it's one factor in deciding to split off a function, the number of times something is repeated shouldn't be the only factor. It often makes sense to create a function for something that's only executed once. Generally, you want to split a function when:

  • It simplifies each individual abstraction layer.
  • You have good, meaningful names for the split-off functions, so you don't usually need to jump around between abstraction layers to understand what's going on.

Your examples don't meet that criteria. You're going from a one-liner to a one-liner, and the names don't really buy you anything in terms of clarity. That being said, functions that simple are rare outside of tutorials and school assignments. Most programmers tend to err too far the other way.

2 of 15
106

Only if the duplication is intentional rather than accidental.

Or, put another way:

Only if you would expect them to co-evolve in the future.


Here's why:

Sometimes, two pieces of code just happen to become the same even though they have nothing to do with each other. In that case you must resist the urge to combine them, because the next time someone performs maintenance on one of them, that person will not expect the changes to propagate to a previously-nonexistent caller, and that function may break as a result. Hence you have to only factor out code when it makes sense, not whenever it seems to reduce code size.

Rule of thumb:

If the code only returns new data and doesn't modify existing data or have other side effects, then it's very likely to be safe to factor out as a separate function. (I can't imagine any scenario in which that would cause a breakage without entirely changing the intended semantics of the function, at which point the function name or signature should change too, and you'd need to be careful in that case anyway.)

🌐
Python for Everybody
py4e.com › html3 › 04-functions
PY4E - Python for Everybody
This script computes the square root of 5, but since it doesn’t store the result in a variable or display the result, it is not very useful. Void functions might display something on the screen or have some other effect, but they don’t have a return value.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-functions
Python Functions - GeeksforGeeks
After creating a function in Python we can call it by using the name of the functions followed by parenthesis containing parameters of that particular function.
Published   October 4, 2025
🌐
W3Schools
w3schools.com › c › c_functions.php
C Functions
In the following example, myFunction() is used to print a text (the action), when it is called: ... // Create a function void myFunction() { printf("I just got executed!"); } int main() { myFunction(); // call the function return 0; } // Outputs "I just got executed!" Try it Yourself »
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-return-statement
Python return statement - GeeksforGeeks
December 10, 2024 - A return statement is used to end the execution of the function call and it "returns" the value of the expression following the return keyword to the caller. The statements after the return statements are not executed. If the return statement is without any expression, then the special value None is returned. A return statement is overall used to invoke a function so that the passed statements can be executed.
🌐
Python
docs.python.org › 3 › library › struct.html
struct — Interpret bytes as packed binary data
September 12, 2025 - The module defines the following exception and functions: ... Exception raised on various occasions; argument is a string describing what is wrong. ... Return a bytes object containing the values v1, v2, … packed according to the format string format. The arguments must match the values required by the format exactly. struct.pack_into(format, buffer, offset, v1, v2, ...)¶
🌐
Wikipedia
en.wikipedia.org › wiki › Virtual_function
Virtual function - Wikipedia
1 month ago - Virtual functions are an important part of (runtime) polymorphism in object-oriented programming (OOP). They allow for the execution of target functions that were not precisely identified at compile time. Many programming languages, such as JavaScript and Python, treat all methods as virtual by default and do not provide a modifier to change this behavior.