Ch 9 covers lists — Python's most versatile data structure. Lists are mutable, ordered sequences that can store mixed data types. Learn creation, operations, methods, comprehensions, and nested lists.
Creation: nums = [1, 2, 3], mixed = [1, "hi", True, 3.14], empty = []. Access: nums[0]=1, nums[-1]=3. Slicing: nums[1:3], nums[::-1]. Mutable: nums[0] = 10 works! Operations: concatenation (+), repetition (*), membership (in). Traversal: for item in nums or for i in range(len(nums)). Comparison: compared element by element. Deep vs shallow copy: a = b (reference — same object), a = b.copy() or a = b[:] (shallow copy — new list, same elements).
Add: append(item) — end, insert(index, item) — position, extend(list) — add all items. Remove: remove(value) — first occurrence, pop(index) — by index (returns item), del list[index], clear() — empty list. Order: sort() — ascending (in-place), sort(reverse=True) — descending, reverse() — reverse order. sorted(list) returns new list. Useful: len(), min(), max(), sum(), count(value), index(value). List comprehension: squares = [x**2 for x in range(10)], evens = [x for x in nums if x%2==0]. Nested lists: matrix = [[1,2,3],[4,5,6],[7,8,9]], matrix[1][2] = 6.
Download: https://ncert.nic.in/textbook/pdf/kecs109.pdf | Complete Book: https://ncert.nic.in/textbook/pdf/kecs1ps.zip
sort() is a list method — sorts the list in-place (modifies original list), returns None. nums.sort(). sorted() is a built-in function — returns a NEW sorted list, original unchanged. new = sorted(nums). Both accept key and reverse parameters: sort(key=len) — sort by length, sort(reverse=True) — descending. Use sort() when you don't need the original order. Use sorted() when you need both original and sorted versions, or when working with non-list iterables (tuples, 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 →