Build Your Own Commands
Understand how to define and use functions with arguments.
We’ve been using built-in functions like print()
and input()
. Now it’s our turn to create our reusable commands using functions.
Think of a function like a recipe:
It has a name.
It can take ingredients (inputs).
It does something when you use it.
Built-in vs. user-defined functions
Built-in functions are already provided by Python, like
print()
orlen()
.User-defined functions are ones you create using the
def
keyword.
Creating your functions lets you:
Reuse your code.
Organize your program.
Make it easier to read and understand.
Writing our first function
You’re about to create a simple function that says hello.
Get hands-on with 1400+ tech skills courses.