My Notes
My Notes
2. 2. User-defined functions:
These functions are defined by the user and can be used in any Python program. To define a
user-defined function, you use the def keyword followed by the function name, parameters,
and a colon. The body of the function is indented and ends with a return statement.
3. 3. Lambda functions:
These are anonymous functions that can be defined on the fly. Lambda functions are typically
used for short, one-off functions. To define a lambda function, you use the lambda keyword
followed by the parameters and the expression to be evaluated.
4. 4. Generator functions:
These functions generate a sequence of values one at a time. Generator functions are typically
used for iterating over large datasets or for creating infinite sequences. To define a generator
function, you use the def keyword followed by the function name, parameters, and a
colon. The body of the generator function contains a yield statement.