Ch 8 covers strings comprehensively — creation, accessing characters, slicing, operations, traversal with loops, built-in methods, and formatting techniques.
Creation: s = "Hello" or s = 'Hello' or s = """multi-line""". Indexing: s[0]="H", s[-1]="o". Slicing: s[1:4]="ell", s[:3]="Hel", s[2:]="llo", s[::-1]="olleH" (reverse). Operations: concatenation s1+s2, repetition s*3, membership "ell" in s → True. Traversal: for ch in s: print(ch) or for i in range(len(s)): print(s[i]). Immutable: s[0]="h" → TypeError. Create new string instead: s = "h" + s[1:].
Case: upper(), lower(), capitalize(), title(), swapcase(). Search: find(sub) → index or -1, index(sub) → index or ValueError, count(sub) → occurrences. Modify (return new): replace(old, new), strip(), lstrip(), rstrip() — remove whitespace. Split/Join: split(sep) → list, "sep".join(list) → string. Check: isalpha(), isdigit(), isalnum(), isspace(), isupper(), islower(), startswith(), endswith(). Formatting: f"Name: {name}, Age: {age}" (f-strings, Python 3.6+), "{}".format(value), %-formatting (older).
Download: https://ncert.nic.in/textbook/pdf/kecs108.pdf | Complete Book: https://ncert.nic.in/textbook/pdf/kecs1ps.zip
Immutability means once a string is created, it cannot be changed in place. Reasons: (1) Hashability — strings can be dictionary keys because their hash never changes. (2) Security — strings used for file paths, URLs, etc. can't be accidentally modified. (3) Performance — Python can cache and reuse string objects (string interning). (4) Thread safety — immutable objects are safe to share between threads. When you "modify" a string, Python actually creates a new string object. This is why string operations return new strings.
Book a Trial + Diagnostic session. Get a personalized Learning Path with clear milestones, tutor match, and a plan recommendation — all within 24 hours.
Book Trial + Diagnostic →