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

  1. Introduction to Programming & Python
  2. Your First Python Program
  3. Variables — Your Data Containers
  4. Data Types — Kinds of Values
  5. Operators & Expressions
  6. Conditional Statements
  7. Loops & Iterations
  8. Functions
  9. Lists — Collections of Data
  10. Dictionaries & Classes
  11. Strings — Working with Text
  12. Error Handling
  13. Mini-Projects & Practice