To get the return value from the Python function, you have to use the return
statement. All Python functions return the value None if there is no return statement.
def fun(): statements . . return [expression]
Python function return value
Simple example code.
def my_func(x):
return 5 * x
print(my_func(3))
print(my_func(5))
print(my_func(9))
Output:
Python Function without return statement
def print_something(s):
print('Printing:', s)
res = print_something('Hi')
print(f'A function without a return statement returns {res}')
Output:
Printing: Hi
A function without a return statement returns None
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.