+ 1
How did this code work? - small question
This is clearly an easy code and understandable. But for some reason, I don't get it. ............................................................. def my_min(*args): return min(args) print(my_min(8, 13, 4, 42, 120, 7)) .............................................................. My question here is where did we get the function 'min' and how did the output give '4' Thank you for your time, have a great day!
3 Answers
+ 9
just to give this information additionally to the post of Lamron :
> variable / parameter *args* is of type *tuple*, so it looks like: (8, 13, 4, 42, 120, 7).
min(args) returns: 4.
+ 5
Hello.
* Inside a function before the parameter means that this parameter can take any amount of numbers/strings inside that argument.
In here, we have a group of numbers: 8,13,4,42,120,7 â These will all be assigned to *args parameter. Therefore args parameter will have thee values.
min() is a built-in python function. Looks at the smallest value in a group of values.
It goes through the parameter *args and selects the smallest value, which is 4
+ 2
Thanks @Lothar , @Lamron