Let’s say you have a piece of code that is repeated multiple times in your program like so.
Code:
print(“I have a message”)
print(“I have a message”)
print(“I have a message”)
Now if you want to change your message you will need to change each instance of it, you can avoid this by creating a function, a function allows you to create a set of code to be ran every time the function is called you use def to create a function like so
Code:
def firstFunction():
print(“I have a message”)
firstFunction()
firstFunction()
firstFunction()
Now if you want to change the message you simply need to alter the function’s code. You can even add further parameters to the function to be used, I will go into further detail on that in my next post!