Functions are blocks of code logic that can be used multiple times within a program, simply by calling the function's name. If you don't use functions, but you want to repeat an operation multiple times, you will have to copy and paste the necessary code multiple times to get your program to work. If you ever have to revise the program, you would have to ensure that all applicable copied and pasted code is updated. With functions, a single code block can be updated. The following is an example of a function:
Preceding screenshot is about as simple as it gets. On line 1, we use the def keyword to define the function called square_num() (the parentheses indicate that it's a function rather than a statement) and tell it that the argument called x will be used for processing. Then we actually define what the function will do...