Regular Expressions in Python (re Module Guide)

Regular expressions in Python: Command Prompt output of re.search, re.match, re.fullmatch, re.findall, re.finditer, re.sub and re.split

Regular expressions in Python are patterns for finding, checking, extracting and replacing text, and they are provided by the built-in re module. re.search(r”\d+”, text) finds the first number in a string, re.findall() returns every match, and re.sub() replaces them. This guide covers every re function, the pattern syntax, groups, greedy and lazy matching, flags, lookarounds, … Read more >>

Python dir() Function: A Practical Guide With Examples

Python dir() Function

When I build a small reporting script, I often receive an unfamiliar object from a library, API response, or custom class. I need to know what that object contains before I can use it safely. Rather than guessing method names or digging through code first, I use the Python dir() function. The dir() function gives … Read more >>

Python dict() Function: A Practical Guide With Examples

Python dict() Function

When I build a small reporting script, I often need a fast way to organize related details. For example, an employee record may need a name, department, email, and monthly sales figure. Keeping those values in separate variables becomes messy quickly. That is where the Python dict() function helps. It creates a dictionary, which stores … Read more >>

Python delattr() Function: Remove Object Attributes

Python delattr() Function

When I build small automation scripts, I often create objects to hold temporary report data—such as a customer’s draft notes, an API token, or a calculated status. Once that information is no longer valid, I do not want it sitting on the object and getting reused accidentally. That is where the Python delattr() function helps. … Read more >>

Python complex() Function: A Practical Guide

Python complex() Function

A few years ago, I worked on a small signal-analysis script for a Chicago engineering team. The input data included values such as 12+5j, and the script needed to calculate magnitudes, phase angles, and combined signals. Regular integers and floats were not enough. That is where Python’s built-in complex() function becomes useful. It creates complex … Read more >>

Python compile() Function: A Practical Guide

Python compile() Function

A few years ago, I built a small reporting utility for a sales team in Austin. The team wanted to save simple calculation rules in a configuration file, such as amount * 0.08 for a commission or units * price for a revenue total. Instead of hard-coding every rule, I needed a controlled way to turn those text expressions … Read more >>

Python classmethod() Function: Complete Guide With Examples

Python classmethod() Function

When I build small reporting tools, I often need to create the same kind of object from different inputs. One report may come from a CSV file, another from a dictionary returned by an API, and another from values entered in the terminal. Creating separate setup code outside the class gets messy fast. The Python classmethod() function … Read more >>

Python chr() Function: A Practical Guide With Examples

Python chr() Function

When I build small reporting scripts, I often need to create clean separators, checkmarks, labels, or encoded text without hard-coding every character. That is where the Python chr() function becomes useful. Give it a number, and it returns the matching character. For example, a CSV cleanup script may need to add a tab character between … Read more >>

Python callable() Function: Check Callables with Examples

Python callable function: Command Prompt output of callable() returning True and False for different objects

The Python callable function, callable(obj), returns True when you can put parentheses after an object and call it, and False when you can’t. Functions, methods, lambdas and classes are callable; numbers, strings and lists aren’t: Every output on this page comes from my own runs on Python 3.12.5, with prices and fees as the sample … Read more >>

Python bytes() Function: A Practical Guide With Examples

Python bytes() Function

When I build small Python automation scripts, I often need to move data between two very different worlds. One side uses readable text, such as a customer name or a JSON response. The other side expects raw binary data, such as a file, an API request body, or a network message. That is where the … Read more >>