Python Tutorial #7: Strings — Methods, Formatting, and Regex Basics
In the previous tutorial, we learned about lists, dictionaries, sets, and tuples. Now let’s take a deep dive into strings — one of the most used data types in Python. We covered string basics in Tutorial #3. This tutorial goes further: advanced methods, formatting tricks, raw strings, and regular expressions. String Methods Strings have many built-in methods. Here are the most useful ones for daily work. Cleaning Text text = " Hello, World! " print(text.strip()) # "Hello, World!" — remove whitespace from both sides print(text.lstrip()) # "Hello, World! " — left side only print(text.rstrip()) # " Hello, World!" — right side only print(text.lower()) # " hello, world! " print(text.upper()) # " HELLO, WORLD! " A common pattern: strip whitespace and normalize case: ...