Question: On page 70 the author shows an example that illustrates using print() versus return. Use that example to explain in your own words, what NoneType
On page 70 the author shows an example that illustrates using print() versus return. Use that example to explain in your own words, what NoneType means and why it appears in the error for that function.
CAUTION Statement return versus Function print(). A common mistake is to use the print() function instead of the return statement inside a function. Suppose we had defined our first function f() in this way: def f(x): print(x**2 + 1) It would seem that such an implementation of function f() works fine: >>> f(2) 5 However, when used in an expression, function f() will not work as expected: >>> 3 * f(2) + 1 5 Traceback (most recent call last): File '
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
