The modern Python regular expressions cheat sheet
This page provides a comprehensive, example-style cheat sheet about regular expressions in Python. I myself use it quite regularly in my work. You can bookmark it to quickly…
Python: Converting a string to lowercase/uppercase
In Python, you can use the str.lower() and str.upper() methods to change the case of all characters in a string to lowercase or uppercase, respectively. These methods have…
Python: 5 ways to check if a string contains a substring
This succinct, practical article will walk you through several different ways to check whether a string contains a specific substring in Python. I assume you already have some…
Python: 4 Ways to Convert a String into a List
This concise, example-based article walks you through four different ways to turn a given string into a list in Python. Life is short, and time is precious; let’s…
Python: 3 Ways to Hash a Password
Overview This concise article shows you three different ways to hash a password in Python. Before seeing the code, let’s clarify some concepts and jargon. This part is…
Python String Slicing: Tutorial & Examples
Overview In Python, string slicing allows you to extract specific portions, or substrings, from a string by specifying the start and end indices. Syntax: Where: Some main points…
Python: 5 Ways to Reverse a String
When writing code with Python, there might be cases where you need to reverse a string, such as when you want to check if a string is a…
Python: Remove leading/trailing whitespace from a string
This concise, straightforward article will show you a couple of different ways to trim leading and trailing whitespace from a given string in Python. Overview You can skip…
4 Ways to Format a String in Modern Python
Using f-strings or formatted string literals (Python 3.6+) This method allows you to embed variables and expressions directly into string literals by prefixing the string with f (that’s…
The modern Python strings cheat sheet
This page provides a comprehensive, example-style cheat sheet about strings in modern Python (Python 3.10 and newer versions). I also use it quite often for quick lookups when…