Module 4: Python CollectionsBeginner18 min read
Python Lists & Methods
Ordered, mutable collections: indexing, append, extend, insert, pop, sort.
Key Takeaways & Core Concepts
- collection of items. Lists can contain elements of different data types, including other lists.
.append(x): Add element to end of list..insert(i, x): Insert element at indexi..pop(i): Remove and return element at indexi(defaults to last item).
Python Lists & Methods
### Python Lists
A list is an ordered, mutable collection of items. Lists can contain elements of different data types, including other lists.
PYTHON Code Example
1languages = ["Python", "JavaScript", "Rust", "Go"]
Click code or "Edit Code" to edit
Interactive Code Block•Tab = 4 spaces•Ctrl + Enter = Run
1 lines
#### Modifying Lists:
.append(x): Add element to end of list..insert(i, x): Insert element at indexi..pop(i): Remove and return element at indexi(defaults to last item)..remove(x): Remove the first occurrence of itemx..sort(): Sort items in place ascending (reverse=Truefor descending)..reverse(): Reverse the list in place.
PYTHON Code Example
1languages.append("Kotlin")
2languages.sort()
3print(languages)
Click code or "Edit Code" to edit
Interactive Code Block•Tab = 4 spaces•Ctrl + Enter = Run
3 lines
List Operations
1fruits = ["apple", "banana", "cherry"]
2fruits.append("orange")
3fruits.insert(1, "mango")
4removed = fruits.pop(2)
5print("Updated fruits:", fruits)
6print("Removed fruit:", removed)
Click code or "Edit Code" to edit
Interactive Code Block•Tab = 4 spaces•Ctrl + Enter = Run
6 lines
Note: insert(1, 'mango') places mango at index 1, shifting subsequent elements.
Practice & AssessmentPython Programming Tutorial
Test Your Understanding
Reinforce core concepts with interactive multiple-choice questions, live coding challenges, and top technical interview questions.
Your Current Score
0 / 0 correct(0 attempted)