Python Function Returning None

后端 未结 5 1976
一整个雨季
一整个雨季 2020-11-22 08:12

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. Any help

5条回答
  •  一生所求
    2020-11-22 08:59

    The other answers have done a good job of pointing out where the error is, i.e. you need to understand that printing and returning are not the same. If you want your function to return a value that you can then print or store in a variable, you want something like this:

    def returnmult(n):
        i = 1
        result_string = ''
        while i <= 10:
            result_string += str(n * i) + ' '
            i += 1
        return result_string
    
    print(returnmult(30))
    

提交回复
热议问题