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
return
statement, you can think of that function like a mathematical function. E.g., the functionf(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.
- 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 includeprint
statements in functions that return a value.