How to Use Lambda Functions in Python

Lambda functions in Python: Command Prompt output of sorted() and max() using a lambda key

To use lambda functions in Python, write lambda, the parameters, a colon and one expression. Python returns that expression’s value automatically, so a lambda is a tiny unnamed function you can pass straight into sorted(), filter() or map(): Quick setup note: my test machine had Python 3.12.5 on Windows 11, and each output block is … Read more >>

Difference Between *args and **kwargs in Python

Difference between *args and **kwargs in Python: Command Prompt output of a function using both

The difference between *args and **kwargs in Python is what they collect. *args gathers any extra positional arguments into a tuple, while **kwargs gathers any extra keyword (name=value) arguments into a dictionary: Version check: Python 3.12.5, Windows Command Prompt. The output blocks are copied straight from those runs. In this tutorial, we’ll cover each one … Read more >>

How to Call a Function from Another File in Python

Python call a function from another file: Command Prompt showing the project folder and the import run

The quickest way to call a function from another file in Python is to keep both files in one folder, import the module by its file name without .py, and call the function. Import the whole module or just one name: I built each project below as a real folder and ran it in Command … Read more >>

Fix the Python 3 Pickle TypeError

a bytes-like object is required not list

When I first started working with the Python pickle module in Python 3, I ran into a frustrating error: This error often happens when we try to use pickle in text mode instead of binary mode. It confused me at first, but after a few trials, I figured out the exact cause and how to … Read more >>

Python Turtle Window

turtle window

As a Python developer with over a decade of experience, I’ve found the Turtle module to be one of the most accessible and fun ways to introduce graphics programming. Whether you’re teaching kids or experimenting with simple visualizations, working with the Python Turtle window is a great starting point. The Turtle window is where all … Read more >>

Remove Decimals from a String in Python

How to remove decimals from a string in Python

Recently, I was working on a project where I had to clean up some messy financial data. The data came from different U.S. retail systems, and many of the values had decimals attached to them inside strings. For example, I had strings like “Product123.45” or “Invoice-567.89”. What I really needed was just the integer part … Read more >>

How to Unpack a List in Python

python unpack list

While working on a project that involved analyzing customer feedback data from different U.S. states, I had to unpack lists in Python multiple times. At first, it seemed simple, just extract values from a list and assign them to variables. But as my data became more complex, I realized how powerful Python’s list unpacking feature … Read more >>

Convert String To Object In Python

Python Convert String To Object

Recently, I was working on a Python project where I needed to convert a string representation of an object back into an actual object. This is a common challenge, especially when dealing with data from APIs, JSON responses, or configuration files. Converting strings to objects is a crucial skill for any Python developer. While Python … Read more >>

How to Convert Multiline String to Single Line in Python

Convert Multiline String to Single Line in Python

Recently, I was working on a text processing project where I needed to parse large chunks of text that contained multiple lines. The challenge was that I needed all this text in a single line format for my data analysis pipeline. In Python, converting multiline strings to single lines is a common requirement when processing … Read more >>

How to Convert String to UUID in Python?

Convert String to UUID in Python

When working with unique identifiers in Python, I often need to convert strings to UUID objects. This conversion is crucial for database operations, API development, and ensuring data integrity in applications. In this article, I’ll show you multiple ways to convert a string to a UUID in Python, based on my decade of experience working … Read more >>