Listen to the mathematical walkthrough or read along with interactive audio controls
Mathematical Vocabulary & Glossary
Master essential mathematical terms with native pronunciation and examples (12 Terms)
Deep Conceptual Analysis & Models
Comprehensive breakdown of core concepts, charts, and mathematical relationships
| Feature | Python String (`str`) | Python List (`list`) |
|---|---|---|
| Syntax Notation | Quotes `'text'` or `"text"` | Square brackets `[item1, item2]` |
| Mutability | Immutable (cannot modify characters in place) | Mutable (can freely modify, add, delete items) |
| Data Types Allowed | Textual Unicode characters only | Heterogeneous (integers, strings, booleans, lists) |
| Indexing & Slicing | Zero-based `str[0]`, Negative `str[-1]` | Zero-based `lst[0]`, Negative `lst[-1]` |
| Length Function | `len("Python") -> 6` | `len([1, 2, 3]) -> 3` |
• start: Beginning index (included). Default = 0.
• stop: Ending index (EXCLUDED). Default = end of sequence.
• step: Stride increment. Default = 1.
• Example: `nums = [0, 10, 20, 30, 40, 50]`; `nums[1:4]` yields `[10, 20, 30]`. `nums[::-1]` reverses sequence.
• `lst.insert(i, x)`: Insert x at index i.
• `lst.remove(x)`: Remove first occurrence of value x.
• `lst.pop(i)`: Remove and return item at index i.
• `lst.sort()`: Sort in place ascending (`reverse=True` for descending).
• `lst.reverse()`: Invert list order in place.
• `"Py" in "Python"` -> True.
• `10 in [1, 2, 3]` -> False.
• Extremely useful in validation algorithms and conditional filters.
Trace Python code snippets to predict console outputs accurately:
1. Slicing with Exclusive Stop
Code: `letters = ['A', 'B', 'C', 'D', 'E']`; `print(letters[1:4])`. Output: `['B', 'C', 'D']`. Notice that index 4 ('E') is excluded.
2. String Immutability Trap
Code: `s = 'cat'`; `s[0] = 'b'`. Result: Python halts with `TypeError: 'str' object does not support item assignment`. Correct fix: `s = 'b' + s[1:]`.
3. Dynamic List Stack Operations
Code: `stack = []`; `stack.append(1)`; `stack.append(2)`; `stack.pop()`. The `pop()` removes 2; `stack` contains `[1]`.