Newbie needs help understanding functions

Hello All,

I am trying to understand functions.

  1. calc_to_units = 24
  2. name_of_unit = “hours”
  3. def days_to_units(no_of_days):
  4. print(f"{no_of_days} days are {no_of_days * calc_to_units} {name_of_unit}")
  5. days_to_units(int(input('Enter the number of days: ')))

So we def-ine a function and in the brackets we assign a variable ( Line 50.) .
Like: def this_is_function(this_is_variable).
Then we call the function later (line 90) and what ever we put in the brackets in the called function becomes the value of the variable?


Correct, the values you put in parenthesis when calling a function are supplied as the values for its arguments:

#        arguments a and b
#        /  / 
def add(a, b):
  return a + b

print(add(2, 3))
#          \  \
#           \  becomes the value of b
#            becomes the value of a

Or more definitively, the parameters a and b. 2 and 3 are the arguments.

1 Like