What is a String?
In Python, a string (data type str) is a sequence of characters enclosed in single quotes ('...') or double quotes ("...").
Real-world analogy
Text Representation
Stores words, sentences, code, symbols, or even numbers formatted as text.
Zero-Indexed Sequence
Each character has an index position starting at 0.
Immutable
Strings cannot be changed in-place. Modifying a string creates a new string.
Length with len()
Use len(text) to get the total character count.
Key vocabulary
- String Literal โ text enclosed in quotes written directly in your code.
- Character โ a single letter, number, space, or symbol inside a string.
- Immutability โ once created, a string's internal content cannot be altered.
- Escape Sequence โ special characters preceded by a backslash like
\n(newline) or\"(quote).
๐งช Compact String Playground
Run the script below to inspect a string and check its character count using len():
๐งช Compact String Playground
Ready to run
No variables yet.
Run your Python code to see them appear here live!
No variables yet.
Run your Python code to see them appear here live!