Basics of functions in Python 3
How to define a function is what is covered in this post.
Let us start by using def for writing a function and remember to use indents and lower case. It is to prevent errors.
It is not enough to just define a function. Python will not execute the function unless it is called for. So, a print command alone is not enough.
How to call for is shown in the screenshot below.
As you can see, the say_hi is the part that calls for the print to be executed by Python.
Suppose you want to add more information and print it out at the same time. This is called for in the case of large data. '
So, it is just enough to add more information.
Please study the screenshot below.
Return statement
The return statement helps you to use Python to execute functions.
Look at how the cube of a number is printed out.
What if we enter result as code before the print statement, we get the same result anyways
The return statement sort of ends the code and any command written after it will not get executed. It means that the code is done.
As you note, the print code was not executed.
All images are screenshots of google colab which is easier to use if you do not want to download Python.