Functions in Python
In the previous lesson, we learned about Loops and how they help repeat blocks of code efficiently. Today, we will learn about Functions, which are used to organize and reuse code in Python programs.
Functions are very important because they make programs cleaner, easier to manage, and reusable.
What are Functions?
A Function is a block of code that performs a specific task.
Instead of writing the same code multiple times, a function allows you to write it once and reuse it whenever needed.
Why Functions are Important
Functions help programmers:
Reduce code repetition
Improve readability
Organize programs
Reuse code
Simplify debugging
Make programs modular
Defining a Function
Python uses the "def" keyword to create functions.
Syntax
def function_name (): # code block
Enter fullscreen mode
Exit fullscreen mode
Example
def greet (): print ( " Welcome to Python " )
Enter fullscreen mode
Exit fullscreen mode
This function is created but will not run until it is…