0
PYTHON ARGUMENTS RETURN TYPE
What is the return of the following? *args **kwargs
6 Antworten
+ 6
Collin Raymund
did you even click on any of the links given by Ausgrindtube ? The answers are all there ...🙄
*args is just a convention. You can as well use *a or *anything. Functions using this parameter type are called variadic functions.
The important part is the operator '*' at the beginning. This means you can pass any number of arguments to the function. They will be treated as a TUPLE.
def foo(*whatever):
print(whatever)
foo(1,2,3,4,5)
will print:
(1, 2, 3, 4, 5)
foo(1)
will print
(1, )
so if you want a function where you can't predetermine the number of arguments you will get, you can use this type of parameter.
**kwargs is similar. kwargs is the convention but can be any variable. The important part is the '**' in front. This will let you input any number of named arguments. In the function, they will be converted to a DICTIONARY .
def foo(**kw):
print(kw)
foo(a=1,b=2,c=3)
will print
{'a': 1, 'b': 2, 'c': 3}
https://realpython.com/JUMP_LINK__&&__python__&&__JUMP_LINK-kwargs-and-args/
+ 6
https://sololearn.com/compiler-playground/c00p15f2WnFY/?ref=app
+ 5
It depends on what arguments you are sending to the code.
Let's see if there's some info in the forum for you:
https://sololearn.com/compiler-playground/W0uW3Wks8UBk/?ref=app
https://www.sololearn.com/discuss/3195985/?ref=app
https://www.sololearn.com/discuss/563561/?ref=app
https://www.sololearn.com/discuss/2821901/?ref=app
https://www.sololearn.com/discuss/3271258/?ref=app
https://www.sololearn.com/discuss/1820630/?ref=app
+ 2
????
0
lets you put multuple arguements in a function Collin Raymund
0
yo