Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Function Returning None

My very simple python function is returning None at the end of it and I'm not sure quite why. I've looked at some other posts and still can't figure it out.

Here is my code:

def printmult(n):
    i = 1
    while i <= 10:
        print (n * i, end = ' ')
        i += 1
    
print(printmult(30))
like image 643
srhoades28 Avatar asked Jan 11 '23 07:01

srhoades28


1 Answers

Because in Python, every function returns a value, and None is what is returned if you don't explicitly specify something else.

What exactly did you expect print(printmult(30)) to do? You've asked it to evaluate printmult(30), and then print whatever results from that. Something has to result from it, right? Or were you maybe expecting some kind of exception to be raised?

Please be sure you understand that printing and returning are not the same thing.

like image 90
Karl Knechtel Avatar answered Jan 17 '23 20:01

Karl Knechtel