【发布时间】:2020-10-13 11:10:20
【问题描述】:
我是 python 新手,最近刚刚学习了 *args 和 **kwargs 的基础知识。
当我尝试使用自己的代码进行练习时,出现了一个意想不到的关键字错误,如下所示:
def student_info2(args, kwargs):
print(args)
print(kwargs)
courses = ["Maths", "Statistics"]
module = "Data Science"
students = {"name": "John Price", "age": 27}
welcome_words = {"welcome": "hello and welcome"}
student_info2(*courses, *module, **students, **welcome_words)
TypeError Traceback (most recent call last)
<ipython-input-61-8bc2f643a250> in <module>
7 students = {"name":"John Price","age":27}
8 welcome_words = {"welcome":"hello and welcome"}
----> 9 student_info2(*courses,*module, **students, **welcome_words)
TypeError: student_info2() got an unexpected keyword argument 'name'
我真的不知道为什么会这样,如果有人可以帮助我解决这个问题,我真的很感激。
【问题讨论】:
标签: python function typeerror args keyword-argument