ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)
Set your Publisher ID in src/config/ads.ts to display live ads.
Python Tutorial• 6 min read
Python Lists, Dictionaries & Tuples
Mastering the 4 fundamental built-in collection types
Python provides four built-in collection types: Lists (ordered, mutable), Tuples (ordered, immutable), Sets (unordered, unique), and Dictionaries (key-value pairs).
Lists vs Dictionaries
List: fruits = ["apple", "banana", "cherry"]. Supports .append(), .pop(), slicing fruits[0:2].
Dictionary: person = {"name": "Sara", "role": "Dev"}. Fast O(1) key lookups.
Working with Lists and Dictionaries
# List of courses
courses = ["HTML", "CSS", "JavaScript", "Python"]
courses.append("SQL")
# Dictionary of user data
user = {
"username": "alex99",
"level": 3,
"completed": courses
}
print(f"User {user['username']} has completed {len(user['completed'])} courses.")
print(f"Latest completed course: {user['completed'][-1]}")ADVERTISEMENT
Google AdSense Slot (inContentBanner)
Set your Publisher ID in src/config/ads.ts to display live ads.
Test Yourself With Exercise
Which Python collection type is defined with curly braces {} and stores key-value pairs?