Ch 11 · Strings — Working with Text · Python
Topic 11 of 13 in Python — Complete Tutorial (Beginner) — 3 lessons.
Strings as Sequences of Characters
A string is an ordered sequence of characters, each at a specific position — just like a list, but of letters. The word "Hello" has H at index 0, e at 1, and so on. You can access any character by its index, measure the length with len(), and slice out a portion with the [start:end] syntax. Strings appear everywhere in real programs: names, messages, passwords, search queries, labels.
String Methods Reference
Python strings come with a rich toolbox of methods for cleaning, checking, and transforming text. You call them with a dot after the string. These cover the vast majority of everyday text tasks: changing case, trimming spaces, searching, replacing, and splitting text into a list of pieces.
f-Strings
f-strings (formatted strings) are the modern, preferred way to build text in Python. You put the letter f before the opening quote, then drop variables and even whole expressions directly into the text inside curly braces { }. Python evaluates whatever is inside the braces and inserts the result. This is far cleaner than joining strings with +, and much harder to get wrong.
All topics in Python Beginner
- Introduction to Programming & Python
- Your First Python Program
- Variables — Your Data Containers
- Data Types — Kinds of Values
- Operators & Expressions
- Conditional Statements
- Loops & Iterations
- Functions
- Lists — Collections of Data
- Dictionaries & Classes
- Strings — Working with Text
- Error Handling
- Mini-Projects & Practice