1、函数定义
当定义一个函数时,遵循如下语法规则:
def 函数名称(参数列表):
函数体
上述参数列表为形参,调用函数时传递的为实参。
2、示例
定义一个简单的函数
def add(x,y):
return x+y
调用:
add(1,2)
def cheese_and_crackers(cheese_count,boxes_of_crackers):
print "you have %d cheeses!"%cheese_count
print "you have %d boxes of crackers!"%boxes_of_crackers
print "Man that's enough for a party!"
print "Get a blanket.\n"
print "We can just give the function numbers directly:"
cheese_and_crackers(20,30)
print "OR,we can use variables from our script:"
amount_of_cheese = 10
amount_of_crackers = 50
cheese_and_crackers(amount_of_cheese,amo