2016-11-12 50 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