python function.
python 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.