1. Lambda
Lambda is a keyword in Python used to define functions, more specifically
Anonymous Functions, and such functions are known as Lambda Functions or
Lambda Expressions.
2. • The expression n ** 2 gets evaluated first, and a value gets returned to the identifier square. The
identifier square can now act as a function, and thus we can pass any number as an argument to find
the square of a number.
5. Keep in mind that the map can take any iterable as an argument and not only a list.
8. • Summary
• Lambda
• Function with many arguments but only one expression.
• It helps to make our code pythonic and to create function wrappers.
• Map
• A function that applies a given function to each item of an iterable and
returns an iterator.
• It provides a faster way to transform an iterable based on the given condition.
• It can have multiple iterables.
• Filter
• It has the same syntax as the map function.
• It helps in extracting items from an iterable based on the given condition.
9. • Decorators
• A decorator is a design pattern in Python that allows a user to
add new functionality to an existing object without modifying its
structure. Decorators are usually called before the definition of
a function you want to decorate.
• Functions in Python are first class citizens. This means that
they support operations such as being passed as an argument,
returned from a function, modified, and assigned to a variable.
This is a fundamental concept to understand before we delve
into creating Python decorators.
• Before we learn about decorators, we need to understand a few
important concepts related to Python functions. Also,
remember that everything in Python is an object, even functions
are objects.
13. Here, we have created two functions:
•ordinary() that prints "I am ordinary"
•make_pretty() that takes a function as its argument and has a nested function named inner(), and returns
the inner function.
We are calling the ordinary() function normally, so we get the output "I am ordinary".
16. Here, the ordinary() function is decorated with the make_pretty() decorator using the @make_pretty syntax, which is
equivalent to calling ordinary = make_pretty(ordinary).