Skip to content

Python void function

  • by

Python void function is not the same as functions you see in C, C++, or Java. If the Python function does not have any return statement then a special value None returns.

Note: void is not a keyword in Python or a type for functions\methods that return nothing.

Python void function

A simple example code shows that void functions return None.

def foo():
    pass


def goo():
    return None


# Now try the following
print(foo())
print(goo())

Output:

Python void function

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.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading