0

PYTHON ARGUMENTS RETURN TYPE

What is the return of the following? *args **kwargs

14th Oct 2024, 6:13 AM
Collin Raymund
Collin Raymund - avatar
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/
14th Oct 2024, 9:04 AM
Bob_Li
Bob_Li - avatar
+ 6
https://sololearn.com/compiler-playground/c00p15f2WnFY/?ref=app
14th Oct 2024, 11:09 AM
Bob_Li
Bob_Li - avatar
+ 2
????
14th Oct 2024, 6:13 AM
Collin Raymund
Collin Raymund - avatar
0
lets you put multuple arguements in a function Collin Raymund
15th Oct 2024, 1:31 AM
Xmosity
0
yo
15th Oct 2024, 10:23 AM
Toha nur
Toha nur - avatar