0% found this document useful (0 votes)
1 views9 pages

Python Functions

A Python function is a reusable block of code that performs a specific action and enhances modularity and code reuse. Functions can be built-in, defined in modules, or user-defined, and are created using the 'def' keyword followed by the function name and parameters. Additionally, Python supports recursive functions, allowing a function to call itself for tasks such as calculating the factorial of a number.

Uploaded by

beyondd.bold
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views9 pages

Python Functions

A Python function is a reusable block of code that performs a specific action and enhances modularity and code reuse. Functions can be built-in, defined in modules, or user-defined, and are created using the 'def' keyword followed by the function name and parameters. Additionally, Python supports recursive functions, allowing a function to call itself for tasks such as calculating the factorial of a number.

Uploaded by

beyondd.bold
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Functions

DR. ARCHANA RAJE


Python-Functions
➢ A Python function is a block of organized, reusable code
that is used to perform a single, related action.
➢ Functions provide better modularity for your application
and a high degree of code reusing.
➢ A Python function may be invoked from any other function
by passing required data (called parameters or arguments).
➢ The called function returns its result back to the calling
environment.
Types of Python Functions:
Python provides the following types of functions −
➢ Built-in functions
➢ Functions defined in built-in modules
➢ User-defined functions
Defining a Function in Python
Here are simple rules to define a function in Python:
➢ Function blocks begin with the keyword def followed by the function name and
parentheses ( ( ) ).
➢ Any input parameters or arguments should be placed within these parentheses. You can
also define parameters inside these parentheses.
➢ The first statement of a function can be an optional statement; the documentation string of
the function or docstring.
➢ The code block within every function starts with a colon (:) and is indented.
➢ The statement return [expression] exits a function, optionally passing back an expression to
the caller. A return statement with no arguments is the same as return None.
Create a Function
Working of Python Function
Python Function with Arguments
The Return Statement
Python Recursive Function
In Python, we know that a function can call other functions. It is even possible for the function
to call itself. These types of construct are termed as recursive functions.
The following image shows the working of a recursive function called recurse.
Factorial of a number

You might also like