Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

How to return none from Python function?

It is found that some functions in python exist purely to perform certain actions rather than to calculate and return something. How do such functions return none and what are they called?


1 Answer
Rajendra Dharmkar

Functions without a return statement known as void functions return None from the function. To return a value other than None, you need to use a return statement in the functions; and such functions are called fruitful functions.

Values like None, True and False are not strings: they are special values and keywords in python and are part of the syntax.

If we get to the end of any function and we have not explicitly executed any return statement, Python automatically returns the value None.

Some functions exists purely to perform actions rather than to calculate and return a result. Such functions are called procedures.

One sample code is given below that returns None.

def lyrics(): pass
a = lyrics()
print a

OUTPUT

None
Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.