''' Purpose: introduce modules. the module defines two functions add() and negate(). they are available to other python files that import harb.py ''' # new keyword def starts in column 1 # we define functions with parentheses - the name of this function is add(), and it has 2 parameters, a and b # if we get any number of input arguments that is not 2, the function will not run def add( a, b ) : # function named add(), parameters named a and b ( names don't super matter! ) ''' Returns value of a + b ''' # the parameters are initialized before the code starts running to the values that we pass in during invokation # this is called pass by value, when we pass copies of the inputs in. the function cannot change the original result = a + b # compute value of interest return result # function hands back its result # once we hit the return statement, we exit the function and go back to the program that this was invoked in, # likely inger.py # any code after a return will not be run # can we change the meaning of these functions in inger.py? no. they are defined here, when we call them inger.py is # paused and we come to harb.py where the code of the function is. even if we defined a different add() function in # inger.py , since we specifically call harb.add() in inger.py, we will still run this function # you can run code in modules! you can define functions and then use them in the same file def negate( x ) : # function named negate(), parameter named x ''' Returns inverse of x ''' result = -x # compute value of interest return result # function hands back the inverse