Blog Post #108: lambda vs. def: When to Use Which

In Post #106 and Post #107, we explored lambda functions—Python’s tool for creating small, anonymous one-liners. We saw that they are particularly useful as arguments for higher-order functions like sorted(), map(), and filter(). This naturally leads to a question of style and best practice: when should you use a concise lambda, and when should you … Read more

Blog Post #107: lambda in Action: Using it with sorted(), map(), and filter()

In Post #106, we introduced lambda functions as a way to create small, anonymous, one-line functions. We mentioned that their primary purpose is to be used as quick, “throwaway” functions that are passed as arguments to higher-order functions. In this post, we’ll see exactly what that means. We will explore three of Python’s most common … Read more

Blog Post #105: An Introduction to Nested Functions

In Post #104, we learned that functions in Python are “first-class citizens,” meaning they can be treated like any other object—assigned to variables, stored in lists, and even passed to other functions. This flexibility allows for some powerful structural patterns, one of which is the ability to define a function inside of another function. In … Read more

Blog Post #104: Functions as First-Class Citizens

So far, we’ve thought of functions as blocks of code—like recipes that we define and call upon to perform a task. But in Python, they are much more than that. Python treats functions as first-class citizens, which is a profound concept that unlocks many advanced and elegant programming patterns. In this post, we’ll explore what … Read more

Blog Post #103: The Full Function Signature: Ordering All Argument Types

In our journey through functions, we’ve encountered several types of parameters: standard positional parameters, parameters with default values (Post #89), the catch-all *args (Post #101), and the catch-all **kwargs (Post #102). A natural question arises: “Can we use all of these in a single function?” The answer is yes! But Python is very strict about … Read more

Blog Post #101: Taking a Variable Number of Arguments with *args

So far, every function we’ve written has had a fixed number of parameters. A function defined with def my_func(a, b): requires exactly two arguments, no more and no less. But many real-world problems require more flexibility. Think about Python’s built-in print() function. You can give it one argument (print(“hello”)), or five (print(1, 2, 3, 4, … Read more