Example Lab FAQ
Feb 7, 2020
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.
- When a function includes a
returnstatement, you can think of that function like a mathematical function. E.g., the functionf(x) = 2*xwould be defined in Python as:def f(x): return 2*xThe 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.
- When a function includes
printstatements, that function is being used as a simple output feature of a program, outputting text to the shell window. We usually don’t includeprintstatements in functions that return a value.