Function returns None without return statement

后端 未结 7 1827
北荒
北荒 2020-11-21 06:19

I just learned (am learning) how function parameters work in Python, and I started experimenting with it for no apparent reason, when this:

def jiskya(x, y):
         


        
7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-21 06:37

    Ya, basically you are using print statements in your function as a way to return information. You shouldn't do this. Print is NOT the same as a return statement. If you simply want your function to give your answer without the none, just type jiskya(2, 3) instead. You will see what the function throws out because you have print statements in the function. If instead you typed "return" in your function, it wouldn't give you anything without the "print" preceding the function call.

提交回复
热议问题