Ojasa Mirai

Ojasa Mirai

Python

Loading...

Learning Level

🟒 BeginnerπŸ”΅ Advanced
🎯 Why Data Structures MatterπŸ“‹ Lists: Ordered CollectionsπŸ”‘ Dictionaries: Key-Value PairsπŸŽͺ Sets: Unique Values & SpeedπŸ“¦ Tuples: Immutable Sequencesβš–οΈ Comparing All Data StructuresπŸ”§ Mastering List Methods⚑ Advanced Dictionary PatternsπŸ”„ Power of Set OperationsπŸ—οΈ Building Nested Structuresβš™οΈ Performance Tuning & Optimization
Python/Data Structures/Lists And Indexing

πŸ“‹ Lists and Indexing β€” Ordered Collections

Lists store multiple items in a specific order, and you access them using their position (index).


🎯 Creating Lists

A list is a collection of items enclosed in square brackets, separated by commas. Order matters!

# Empty list
empty_list = []

# List of numbers
numbers = [10, 20, 30, 40, 50]

# List of strings
colors = ["red", "green", "blue"]

# Mixed data types
mixed = [1, "hello", 3.14, True]

πŸ’‘ Understanding Indexing

Python uses zero-based indexingβ€”the first item is at position 0, not 1. You access items using square brackets with the index.

fruits = ["apple", "banana", "orange", "grape"]

print(fruits[0])   # apple (first item)
print(fruits[1])   # banana (second item)
print(fruits[3])   # grape (fourth item)
print(fruits[-1])  # grape (last item, negative index)
print(fruits[-2])  # orange (second from last)

🎨 Real-World Example: Grade Tracking

# Student's test scores in order
grades = [85, 92, 78, 88, 95]

# Access specific grades
first_test = grades[0]  # 85
last_test = grades[-1]  # 95

# Find average
average = sum(grades) / len(grades)
print(f"Average: {average}")  # Average: 87.6

πŸ“Š Indexing Visualization

fruits = ["apple", "banana", "orange", "grape"]

Index:     0         1          2         3
          ↓         ↓          ↓         ↓
List:   apple    banana     orange    grape
          ↑         ↑          ↑         ↑
Negative: -4       -3         -2       -1

πŸ”‘ Key Takeaways

  • βœ… Lists store ordered items in square brackets
  • βœ… Indexing starts at 0 (not 1)
  • βœ… Negative indices count from the end
  • βœ… Use `len()` to find the number of items

Ready to practice? Challenges | Quiz


Resources

Python Docs

Ojasa Mirai

Master AI-powered development skills through structured learning, real projects, and verified credentials. Whether you're upskilling your team or launching your career, we deliver the skills companies actually need.

Learn Deep β€’ Build Real β€’ Verify Skills β€’ Launch Forward

Courses

PythonFastapiReactJSCloud

Β© 2026 Ojasa Mirai. All rights reserved.

TwitterGitHubLinkedIn