Print vs. Return

Print Statement: As you saw on the previous page the print statement converted the number i into a string and printed it to the command line. This is more or less the equivalent of "say" in Snap!. Print statements allow a programmer to print values and variables at a chosen location in the code.


>>> x = 5
>>> print(x)
5
                    

Return: If print is Python's version of "say", then return is Python's version of "report". return should be used when you want to end a function and report a value.


>>> def times_5(x):
...     return 5 * x
...
>>> times_5(3)
15
>>> times_5(3) + 2
17
                    

If you're testing a function in Python like above, the interpreter will often print the return value so you can see what it was.