相关疑难解决方法(0)

如何在python中将字典项作为函数参数传递?

我的代码

第一档:

data = {'school':'DAV', 'standard': '7', 'name': 'abc', 'city': 'delhi'}
my_function(*data)
Run Code Online (Sandbox Code Playgroud)

第二档:

my_function(*data):
    schoolname  = school
    cityname = city
    standard = standard
    studentname = name
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,只传递了"data"字典的键my_function(),但我希望键值对能够通过.怎么纠正这个?

我想要my_function()像这样修改

my_function(school='DAV', standard='7', name='abc', city='delhi')
Run Code Online (Sandbox Code Playgroud)

这是我的要求,根据这个给出答案

编辑:字典键类更改为标准

python dictionary function python-2.7

65
推荐指数
3
解决办法
15万
查看次数

标签 统计

dictionary ×1

function ×1

python ×1

python-2.7 ×1