Lab 3, Part 1: print, return, and None
Summary
print
causes characters to be displayed in the shell (the bottom pane of your Thonny window)return
specifies the result of the function invocation- a function without an explicit
return
statement returns the specialNone
value (which Python typically does not print)
Here is the worksheet as a google doc Open the document, then File -> Make a Copy. Then you can edit your copy with your answers.
Examine the following functions. Which are fruitful and which are None functions?
def hello(x):
print('--', x, '--')
def square(x):
return x * x
def showSquare(num):
print('The argument of square is ' + str(num))
return square(num)
Predict the outcome of the invocations below:
>>> hello('froggy')
>>> print(hello('bunny'))
>>> square(3) + square(4)
>>> square(square(3))
>>> showSquare(5)
>>> showSquare(3) + showSquare(4)
>>> hello('frog') + hello('toad')