As your programs get longer, it becomes important to organise your code into smaller, reusable parts. That’s where functions come in. A function is a named block of code that does a specific job — like displaying a message, calculating a total, or checking a password. Once you write a function, you can run it any time by “calling” it.
In this lesson, you’ll learn how to define a function using def, give it a name, and pass in information using parameters. You’ll also learn how to return results from a function so they can be used elsewhere in your program. Functions make your code easier to read, reuse, and debug — and they’re essential for building larger projects.