Example Lab FAQ

An example FAQ entry for Lab 1. I will often post answers to frequently asked questions from office hours. Check in here if you have a question, there might be an answer already available! For example, in past years I have observed confusion between print and return.

  1. When a function includes a return statement, you can think of that function like a mathematical function. E.g., the function f(x) = 2*x would be defined in Python as:
     def f(x):
         return 2*x
    

    The expression f(7) has the value 14.

    This function does not print anything. The caller of the function could use the returned value (e.g., in a computation) or maybe print it, but the function itself does not print.

  2. When a function includes print statements, that function is being used as a simple output feature of a program, outputting text to the shell window. We usually don’t include print statements in functions that return a value.