“ args”和“ kwargs”在touple,list和dictionary之间的哪个用途?

时间:2018-09-25 14:37:14

标签: python

我应该清楚我可以使用的两种方法。

正确的答案是什么:

is both are touple

args is tuple and kwargs is dictonary 

args is dictonary and kwargs is tuple

args is list and kwargs is tuple

both are list

2 个答案:

答案 0 :(得分:4)

好吧,假设您谈论function arguments and keyword arguments,请尝试一下:

$hour

因此,>>> def foo(*args, **kwargs): ... print(type(args)) ... print(type(kwargs)) ... >>> foo(1,2,x=3,y=4) <class 'tuple'> <class 'dict'> args,而tuplekwargs

答案 1 :(得分:0)

args是元组而kwargs是字典是正确的答案。

看一下代码:

def findType(*args, **kwargs):
    print(type(args))
    print(type(kwargs))
findType(4,6,x=12, y=45)

该代码类似于上述代码。我假设您是新手,并且需要有关代码的简单摘要。

首先,我们有一个函数调用Find Type As作为参数,我们采用两个值。实际上,我们通过使用type Function来找到两个值的类型。