Python Functions
Presentation
Introduction
A function in Python is a block of reusable code that performs a specific task. Functions help make
programs modular, readable, and efficient.
Prepared By:
Muhammad Awais
Saqib Ali
Muneeb
Muhammad Shabaz
Why Use Functions?
• Code reusability
• Improves readability
• Reduces code duplication
• Easy debugging and maintenance
Types of Functions in Python
• Built-in functions (print, len, type)
• User-defined functions
Defining a Function
A function is defined using the def keyword followed by the function name and parentheses.
Example: def my_function():
Function Parameters
Parameters are values passed to a function to perform operations.
Example: def add(a, b):
Return Statement
The return statement is used to send a result back from a function.
Example: return a + b
Calling a Function
To use a function, you need to call it by its name followed by parentheses.
Example: result = add(3, 5)
Advantages of Functions
• Saves time
• Makes code organized
• Easy to understand and reuse
Conclusion
Python functions are essential for writing clean, efficient, and reusable code. They help
programmers break down complex problems into simple parts.