Functions – Advanced In earlier lessons we saw how to define and call functions in Python. Now let’s go deeper into features that make Python functions powerful, flexible, and closer to what you may know in JavaScript (like closures, callbacks, arrow functions). Default Parameters Like JS, Python allows default values. Keyword Arguments Unlike JS (where order matters unless you pass an object), Python supports keyword arguments . Arbitrary Arguments ( and ) collects extra positional arguments into a tuple. collects extra keyword arguments into a dictionary. Output: This is like JS’s operator. Lambda Functions Equivalent to JS arrow functions, but syntax is shorter. Use them for short, throwaway functions (filters, maps, sorting). Closures Functions can capture variables from outer scopes, similar to JS. Higher-Order Functions Functions can take other functions as arguments (same as JS). Annotations & Type Hints You can annotate parameters and return values. These are not enforced at runtime , but tools like mypy or IDEs use them for static checks. Docstrings Functions can have built-in documentation strings. Access with or . Generators as Functions We saw earlier. Any function using is a generator function. Decorators A decorator is a function that wraps another function to add behavior, similar to higher-order functions in JS. Output: This is like middleware or function wrappers in JS. Example – Function Registry for Inventory Actions ✅ Why it matters : Functions in Python are first-class citizens , like JS. Features like , , lambdas, closures, and decorators make them extremely flexible. In real-world apps, decorators are widely used for logging, auth, validation, caching — exactly like middleware or wrappers in JS.