Working with Strings
Strings and String Operations
Part of: Variables, Lists & Procedures
A string is a sequence of characters, text like "Hello", "42", or even an empty "". Strings are how programs handle names, messages, and any data made of letters and symbols. Strings are ordered like lists Characters in a string have indexes , exactly like list elements. Zero-indexed, with negative indexes counting from the end: Because they are ordered sequences, you can traverse a string with a loop: Common string operations - Concatenation with + joins strings: "Ada" + " " + "Lovelace" → "Ada Lovelace". - Repetition with : "ab" 3 → "ababab". - Length : len(s) counts characters. - Case : s.upper() and s.lower() return new strings; the original is unchanged. - Slicing : s[1:4] takes characters 1 up to (not including) 4. s[::-1] reverses the whole string. Strings are immutable You cannot change a character in place: name[0] = "A" raises an error. Instead you build a new string . To count or transform characters, loop and accumulate: Why it matters Real data is full of text: usernames, sentences, DNA sequences, file contents. Treating a string as an ordered, traversable sequence, combined with concatenation, slicing, and case methods, lets you validate input, format output, and sear
Challenge: Reverse and Count Vowels