
说明
1、缺省参数的定义位置,要保证带有默认值的缺省参数在参数列表末尾。
2、调用函数时,如果有多个缺省参数,需要指定参数名称。
实例
defprint_info(name,title="",gender=True):
"""
:paramtitle:职位
:paramname:班上同学的姓名
:paramgender:True男生False女生
"""
gender_text="男生"
ifnotgender:
gender_text="女生"
print("%s%s是%s"%(title,name,gender_text))
#提示:在指定缺省参数的默认值时,应该使用最常见的值作为默认值!
print_info("小明")
print_info("老王",title="班长")
print_info("小美",gender=False)