User-Defined Functions
Learn how to make your own functions.
We know that built-in functions (input()
, print()
, int()
, etc.) are like standard ready-to-cook recipes everyone knows how to use. But did you know we can create our own functions as well? We cannot possibly have a ready-made function against every need in the world. Imagine if we wanted to create YouTube, and there was a built-in function BuildYouTubeForMe("please")
? It doesn’t work like that, right? Instead, Python lets us create functions of our own that we can then use as and whenever required, just like we can use built-in functions.
All in all, functions help create modular and reusable code, such as displaying a standard message, generating random numbers, or performing other predefined tasks.
What are user-defined functions?
Here is the basic structure of a function:
def function_name(parameter1, parameter2):# Function body# ...return result