Skip to content
Advertisement

why returning None in functions python?

first image I was having problem when I run this code I raise exception in function then why none is printing

sec image And in this case none is not printing.. pls help

Advertisement

Answer

when a python function does not have a return statement it automatically return None.

In the first image, the print(numcheck(5)) pass the assert but the function return None so it printed None but print(numcheck(-5)) did raise the exception.

In the second image print(numcheck(-5)) raise directly the exception so python did not print anything.

Advertisement