Loading...
Text is a sequence of characters with a representation and an indexing convention. Separate operations on the text from arithmetic on a value parsed from that text.
What you'll be able to do
String length counts elements according to the language’s representation; indexing identifies a position. Python indexing starts at zero, so the last valid positive index is length minus one. A substring operation returns part of the text; a slice such as name[1:4] includes index 1 and excludes index 4.
Concatenation joins text without performing numerical addition. The strings "12" and "3" concatenate to "123". Searching for a substring requires a convention for failure: Python find returns -1 when absent, so treating that result as a successful index can accidentally access the last character.
A character coding system associates characters with numerical code points. In Python, ord converts a one-character string into its Unicode code point and chr performs the reverse operation. A character code is different from the numeric value described by a digit character.
Consecutive decimal digit characters have consecutive code points, allowing a deliberate conversion in simple contexts. General text needs an encoding when stored as bytes; a Unicode code point is not automatically a single byte. File decoding and in-memory string manipulation are different operations.
Parsing interprets text as a typed value. int("12") yields a whole-number value, whereas str(12) formats a value as text. Invalid syntax can cause an exception; silently replacing every invalid entry with zero changes the meaning of the input.
Date/time conversion requires an agreed format. A date such as 04/05/2026 is ambiguous without a day/month convention. Keep dates as date/time objects when comparing or calculating intervals, and format them for display separately. Document timezone assumptions when an instant rather than a local calendar date matters.
code = "AB-204"
print(len(code))
print(code[3:])
print(ord("5"), int("5"))Scroll horizontally to see the full code or table.from datetime import datetime
value = datetime.strptime("31/10/2026", "%d/%m/%Y")
print(value.strftime("%Y-%m-%d"))Scroll horizontally to see the full code or table.Attempt the task before opening its worked response. Record each change of state, explain the rule used, and check the result against the original requirements. Code examples labelled Python 3 use that language’s conventions; pseudocode states its own assumptions.
Common mistakes to avoid
Key takeaways
Test yourself
Answer a few questions, then review anything you missed.
Start with the quiz above to check the key ideas. You can also choose another topic from the practice library.