函数的参数可以是简单常量,变量或者表达式,见ex19.py:
#!/usr/bin/python
# -*- coding: utf-8 -*-
def countFruit(apple_count, pear_count):
print "You have %d apples and %d pears." %(apple_count, pear_count)
print "Just give the function numbers derectly:"
countFruit(12, 11)
print "Or, use variables from our script:"
capp = 22
cpear = 34
countFruit(capp, cpear)
print "Or, use expression inside:"
countFruit(12+22, 34-11)
print "And combine the two, variables and expression:"
countFruit(capp+99, 99-cpear)
运行:
python ex19.py
有:
Just give the function numbers derectly:
You have 12 apples and 11 pears.
Or, use variables from our script:
You have 22 apples and 34 pears.
Or, use expression inside:
You have 34 apples and 23 pears.
And combine the two, variables and expression:
You have 121 apples and 65 pears.