+ 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!

18th Jan 2023, 3:46 PM
Karim Maasarani
Karim Maasarani - avatar
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.
18th Jan 2023, 4:45 PM
Lothar
Lothar - avatar
+ 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
18th Jan 2023, 4:12 PM
Lamron
Lamron - avatar
+ 2
Thanks @Lothar , @Lamron
22nd Jan 2023, 3:36 PM
Karim Maasarani
Karim Maasarani - avatar