Function returns None without return statement

后端 未结 7 1821
北荒
北荒 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:50

    You are doing two prints, the first one in the corpus of your function and the second one is printing the result of the function, which as actually None.

    You should rather do something like this:

    def yourfunction(x, y):
        if x > y:
            return y
        else:
            return x
    

    Then,

    >>> print yourfunction(2, 3)
    2
    

提交回复
热议问题