Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

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

Continue reading