代码:
def describe_pets(animal_type = 'dog', pet_name):
print("\nI have a " + animal_type + ".")
print("My " + animal_type + "'s name is " + pet_name)
describe_pets(pet_name = 'kane')
错误提示:
non-default argument follows default argument
原因在于将带默认值的形参放在了不带默认值的形参前面,更改顺序即可。
更改后的代码
def describe_pets(pet_name, animal_type = 'dog'):
print("\nI have a " + animal_type + ".")
print("My " + animal_type + "'s name is " + pet_name)
describe_pets(pet_name = 'kane')