A procedure is a named section of code that can be called(run) anywhere within a program.
All procedures have 2 parts:
This is where the code section is separated from the rest of the code and given a name. Defining a procedure does nothing until the code is called.
def hello_world(): print("Nice to meet you world")
We run a procedure by calling it by its name.
hello_world() #This will run the hello_world() procedure.
You can call a function as many times as you like:
while True: hello_world() #This will keep running the function inifitely.
A function is similar to a procedure but with one key difference – it returns a value (or object) to the line where the function was called.
def gimme_five(): return 5
You can choose to do whatever you like with the return value.
print(gimme_five()) #This will print out the number 5 x = gimme_five() #This will take the return value 5 and set x to be 5