12/19 I cant understand


#1

Alright, so 12/19 wants us to understand the code given. I didn’t understand anything, especially arg and arg*. Can someone also explain to me why the console wrote the following?:

10
-10
10

The code is:

  print max(args)
  return max(args)
    
def smallest_number(*args):
  print min(args)
  return min(args)

def distance_from_zero(arg):
  print abs(arg)
  return abs(arg)

biggest_number(-10, -5, 5, 10)
smallest_number(-10, -5, 5, 10)
distance_from_zero(-10)```



Thanks!

#2

*args allows for a tuple (immutable list), this is very useful if you have an unknown number of arguments, we can see this by simple printing args and its type:

def biggest_number(*args):
     print args
     print type(args)

biggest_number(-10, -5, 5, 10)

for more info see:

so the output is caused by getting the max value from args in first function (biggest_number), the minimum value from the second function args, and the absolute (abs) value for the third function


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.