0% found this document useful (0 votes)
2 views

python function.

User-defined functions in Python allow for the encapsulation of repeated tasks, enabling code reuse by calling the function instead of rewriting code. The 'def' keyword is used to declare these functions, while lambda functions provide a concise way to create small, anonymous functions for simple operations. The map() function is useful for applying a function to all elements of an iterable without modifying the iterable directly.

Uploaded by

semilsavaliya12
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

python function.

User-defined functions in Python allow for the encapsulation of repeated tasks, enabling code reuse by calling the function instead of rewriting code. The 'def' keyword is used to declare these functions, while lambda functions provide a concise way to create small, anonymous functions for simple operations. The map() function is useful for applying a function to all elements of an iterable without modifying the iterable directly.

Uploaded by

semilsavaliya12
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

User Define Function

• A function is a set of statements that take inputs, do some specific computation, and
produce output.
• The idea is to put some commonly or repeatedly done tasks together and make a function
so that instead of writing the same code again and again for different inputs, we can call
the function.
• Functions that readily come with Python are called built-in functions. Python provides
built-in functions like print(), etc. but we can also create your own functions. These
functions are known as user defines functions.
• In Python, a def keyword is used to declare user-defined functions.
• An indented block of statements follows the function name and arguments which
contains the body of the function.
In Python, a lambda function is a small, anonymous function that
is defined using the lambda keyword. It can have any number of
arguments but only one expression, which is evaluated and
returned. Lambda functions are often used for short, simple
operations where defining a full function with def is unnecessary.
When to Use map
Use map() when you want to apply a function to all elements of an iterable, and you don't
need to modify the iterable in place. It's particularly useful for transforming data, such as
scaling, formatting, or converting elements.

You might also like