Exercise 2

Comments are a helpful way to explain your code to others and your future self. Take a look at the examples below. Run the cells.

# This is a comment. It helps explain the context of your code and why you made certain decisions
# You can have many lines of comments in a row
my_var = 2 # You can also create 'in-line' comments to explain specific lines
    

Note that output is not generated for these lines.

'''
This is another type of comment, generally used for creating docstrings. 
These help breakdown complex functions, objects, classes and others. 
They can also be referenced as help documentation for functions and modules you
create.
'''
    

Modify the comments in the function below to make them more helpful. If you're not sure, don't worry, we'll learn more about what's happening in this function later.

def add_num(a,b):
    '''
    What does this function do?
    What are the inputs and outputs?
    '''
    total = a + b # what is this line doing? 
    # what am I doing next?
    print(total)
    

You will learn functions later, but notice that our docstring gets saved when we define a function. We can access this later.

print(add_num.__doc__)