Functions Functions are the building blocks of any program. If you know functions in JavaScript, you’ll find Python functions familiar, but the syntax and features differ . Defining a Function JavaScript: Python: Use instead of . Indentation defines the function body. Return values work the same way as in JavaScript. Calling Functions JavaScript: Python: Default Parameters JavaScript: Python: Both languages support default values. Object Parameters vs Dictionaries / Keyword Arguments In JavaScript, you often pass an object to avoid relying on parameter order: In Python, the closest equivalent is a dictionary : Another Python way is using , which collects keyword arguments into a dictionary: Both dictionaries and behave like JS objects. You don’t worry about order, only about the keys. This makes functions more flexible and readable. Mixing Positional and Keyword Arguments In Python, you can combine positional arguments (order matters) and keyword arguments (order doesn’t matter): The first two arguments are positional ( , ). The optional ones ( , ) are given by keywords . This avoids confusion and makes function calls more descriptive. In JavaScript, you’d typically handle this with an object for optional arguments : JS uses default values + object params. Python achieves the same with a mix of positional + keyword arguments. Arbitrary Arguments Sometimes you don’t know how many arguments a function will receive. In JavaScript: In Python: collects arguments into a tuple (like JS rest ). For keyword arguments: collects keyword arguments into a dictionary (similar to JS objects). Argument Unpacking ( args and kwargs in Calls) In JavaScript, you can use the spread operator to expand arrays or objects when calling a function: In Python, is used to unpack a list or tuple into positional arguments: For objects in JavaScript: In Python, you can use to unpack a dictionary into keyword arguments: unpacks sequences (lists/tuples) into positional args. unpacks dictionaries into keyword args. Together, they make Python function calls very flexible, just like the JS spread operator. Return Values Python can return multiple values directly: Equivalent in JavaScript would be returning an array: Anonymous Functions (Lambdas) JavaScript: Python: Lambdas are single-expression functions . Use them for short, inline operations. Nested Functions Python allows defining functions inside functions: This is similar to JS: First-Class Functions Like JavaScript, Python treats functions as values: This is like passing functions in JS: Docstrings (Function Documentation) In JavaScript, you write comments above functions: In Python, you use docstrings inside the function: You can access it later: Quick Takeaway Python functions use instead of . Support default arguments, keyword arguments, and unlimited args with and . Return multiple values naturally (like tuples). Lambdas are like JS arrow functions, but simpler. Functions are first-class: pass them around, nest them, store them in variables. Use docstrings for built-in documentation.