问题重现
# 定义函数
def personInfo(name, age='18', gender='女', weight='76'):
print('名字:' + name)
print('年龄:' + age)
print('性别:' + gender)
print('体重:' + weight)
# 调用
personInfo('东小记', age='20', '男', weight='80')
原因
函数定义的参数列表中必须参数与默认参数不可以混合定义,同理,在调用时也不可以混合传参
解决
# 定义函数
def personInfo(name, age='18', gender='女', weight='76'):
print('名字:' + name)
print('年龄:' + age)
print('性别:' + gender)
print('体重:' + weight)
# 调用
personInfo('东小记', '20', '男', '80')
print('~~~~~~~~~')
personInfo('东小记', age='20', gender='男', weight='80')