首页 > 代码库 > python(2)

python(2)

可变参数

def enroll(name, gender, age=6, city=‘Beijing‘):    print ‘name:‘, name    print ‘gender:‘, gender    print ‘age:‘, age    print ‘city:‘, city

调用:
enroll(‘Bob‘, ‘M‘, 7)enroll(‘Adam‘, ‘M‘, city=‘Tianjin‘)

定义默认参数要牢记一点:默认参数必须指向不变对象!

python(2)