2016-11-12 24 views
-2
def greater_less_equal_5(answer): 
if answer > 5: 
    return 1 
elif answer < 5:   
    return -1 
else: 
    return 0 

print greater_less_equal_5(4) 
print greater_less_equal_5(5) 
print greater_less_equal_5(6) 

這些數字:4,5,6是什麼意思,並在結束打印?這些在打印中意味着什麼?

+1

4,5,6分別作爲參數傳遞到函數中,並且返回的值被打印在屏幕上。請參閱 - https://www.tutorialspoint.com/python/python_functions.htm以瞭解有關功能的更多信息。 –

+1

@RohinGopalakrishnan在OP的例子中,'print'是一個聲明,不是函數。然而,它被改爲了一個函數,在Python 3.x中。 –

回答

2

它們是傳遞給函數greater_less_equal_5的參數/參數,作爲將在該函數體內使用的值answer。例如,greater_less_equal_5(4)有效運行這段代碼:

if 4 > 5: 
    return 1 
elif 4 < 5:   
    return -1 
else: 
    return 0 

這有什麼好做的print