例:
def a(name,age,house=''): if house: b = name.title()+str(age)+house else: b = name.title()+str(age)+'无房' return b print(a('zys',18,'有房')) print(a('zys',18))
>>>Zys18有房 >>>Zys18无房
可给实参指定一个默认值——空字符串,Python将非空字符串解读为True
例:
def a(name,age,house=''): if house: b = name.title()+str(age)+house else: b = name.title()+str(age)+'无房' return b print(a('zys',18,'有房')) print(a('zys',18))
>>>Zys18有房 >>>Zys18无房
可给实参指定一个默认值——空字符串,Python将非空字符串解读为True