Browse by Topic

Popular

Latest

Latest Python Posts

Illustration of a Python string with a magnifying glass counting occurrences of a substring
Python

Python String Count: Counting Substrings and Characters

Learn how to use Python's str.count() to count characters and substrings, handle overlapping matches, and evaluate performance tradeoffs.

PythonString MethodsSubstring CountingText Processing
Illustration comparing Python's find and index methods with a magnifying glass over a string and a list, showing -1 and an error symbol.
Python

Python find vs index: Key Differences

python find vs index: Compare Python's find() and index() methods for strings and lists, and learn when each is appropriate based on error handling and return behavior.

pythonstring methodslist methodserror handling
Illustration of Python string rindex scanning from the end to find the last occurrence of a substring.
Python

Using Python String rindex to Find the Last Occurrence

Python's `str.rindex()` finds the last occurrence of a substring and returns its starting index. This guide covers syntax, practical examples, error handling, and how `rindex` compares with `rfind`.

Pythonstring methodsrindexrfind
Illustration of a Python string represented as colored blocks with one block highlighted to show its index position.
Python

Python String Index: Using str.index() Safely

Learn how to use Python's str.index() method to locate substrings, handle ValueError exceptions, and choose between index(), find(), and in.

Python stringsstr.indexstring methodsexception handling
Illustration of a Python string with a search pointer moving from the right side to locate the last occurrence of a substring.
Python

Using Python string rfind for Right-Side Search

Learn how python string rfind searches from the right, its parameters, return values, and practical differences from find for real-world text processing.

string methodssubstring searchrfindPython standard library
Python string find method locating a substring within a text string, shown as a magnifying glass over a line of code.
Python

Using Python String find() to Locate Substrings

How Python's str.find() locates substrings, including its return value semantics, start/end parameters, and comparisons with index(), in, and re.search().

PythonString MethodsSubstring Searchstr.find
A magnifying glass over a string ending with a suffix, representing the Python endswith method
Python

Python String endswith: Syntax and Usage

Learn how to use Python's str.endswith() method: syntax, tuple suffixes, start and end parameters, and common edge-case mistakes.

string methodssuffix checkingPythonendswith
A stylized illustration of a string being checked for a prefix, with a checkmark indicating a successful startswith match.
Python

Using Python's str.startswith() for Prefix Checks

Learn how to use Python's str.startswith() for prefix checks, including tuple prefixes, start and end indices, performance, and edge cases.

string methodsprefix matchingPython stringstext processing
Illustration comparing Python lower() and casefold() methods with Unicode characters like ß and Σ, showing case-insensitive matching differences.
Python

Python lower vs casefold: Key Differences

Understand the difference between Python's str.lower() and str.casefold() for case-insensitive operations, including Unicode handling and practical examples.

Python stringscasefoldUnicodestring methods
Illustration of Python string casefold normalizing Unicode characters for case-insensitive comparison.
Python

Python String Casefold: Unicode-Safe Case-Insensitive Comparison

Python's casefold() method provides Unicode-safe case-insensitive string comparison, unlike lower(), with practical examples and edge cases.

casefoldunicodestring comparisoncase-insensitive