A function is a block of code you can call repeatedly. Functions often hold complex sets of instructions.
def introduction(your_name):
print("Hello! It's good to see you!")
other_name = input("What's your name?")
print("It's nice to meet you " + other_name + ". I'm " + your_name + ".")
Once defined, using the def keyword, you can call this function to execute the code.
introduction("Mr. McClung")
Sometimes a "simple" action needs difficult code to implement. Replacing the complex code with a function call makes the code easier to read and understand. Often those using a function don't have to understand how a function works, as long as you know what it does.
You can make one change to the function rather than changing your code multiple times if you had copied and pasted those instructions rather than calling a method several times.
Turing a complex set of instructions into a function allows you to reuse that set of instructions rather than writing it again. Functions that use parameters have even more flexibility to be reused and repurposed.
Modular design means we can use simple pieces to build more complex pieces. Those complex pieces can be used to build more complex pieces and so on.
Coding is ultimately about solving problems. Sometimes these problems are large and complicated. One design paradigm to help tackle large problems is starting by stating the problem in a few understandable but complicated steps. Then you can break down those complicated steps into their simpler components.
For example, if you were trying to get fast food, your instructions might look like this:
walk_to(car)
drive_to(restaurant)
order_food(food)
pay(food)
drive_to(home)
walk_to(house)
eat(food)
This is a readable easily understandable series of steps. But each is actually very complicated. How do I walk? How do I drive? Walking requires moving the legs and feet in a specific way. Driving requires acceleration, braking, and steering. But stating the problem in this simple way allows us to divide the problem into separate smaller problems to be solved.