DS 1501 · Lesson 6 of 24
Instructor: Corey Schafer10m
Sign in to watchStore, inspect, slice, and mutate ordered collections of data using Python lists. What you will learn: • Creating heterogeneous or typed lists ([10, 20, 30]) and measuring size with len(). • Positive (0-based) indexing and negative (-1 from right) indexing. • Sublisting / slicing syntax: lst[start:stop:step] (stop is exclusive; reverse with lst[::-1]). • Mutability in place: element assignment (lst[1] = 99), slice replacement, append(), insert(), pop(), and remove(). • List aliasing pitfall (b = a shares reference vs b = a[:] shallow copy). University Outline Mapping: Class 6 · CO2 · Reading: 5.1 (deitel), chapter 3 (crash) · Activities: Lecture, Slides, Demonstration.
Note
Outline: Class 06 | CO2 | Reading: Deitel 5.1 & Crash Course Ch. 3 Slicing Reference Cheat Sheet: nums = [10, 20, 30, 40, 50, 60] nums[1:4] -> [20, 30, 40] nums[-3:] -> [40, 50, 60] nums[::2] -> [10, 30, 50] nums[4:1:-1] -> [50, 40, 30] Exam Trap: Single-element indexing nums[6] raises IndexError, whereas out-of-range slices like nums[2:99] silently clamp.
Same resources as in the community course — sign in to watch the lesson and track progress.
Watch the whole course.
Sign in to play every lesson, track your progress, and ask questions alongside the community.
Already signed in? Open lesson in Community