Ad space (banner)
🐍Python Lessons
Lesson 6 / 69

Working with Lists

This lesson covers the basics of using lists in Python, so you can efficiently work with multiple pieces of data at once. It's written for anyone searching "Python list tutorial" or "Python enumerate usage".

A list is a type that holds multiple pieces of data together. You create one with [ ], and check its length with len(). If you only ever had "one variable, one value," handling 100 names would mean creating 100 separate variables — clearly not practical. enumerate() is handy because it lets you pull out both the index (position number) and the element at the same time.

The sample code creates a list called fruits, uses len() to get its length, and enumerate(fruits, 1) to print a numbered list. The second argument to enumerate() (here, 1) sets what number the count starts from — it defaults to 0 if omitted. Lists are the go-to structure any time you need to manage a group of similar data, like a shopping list or an attendance sheet.

A common beginner mistake is forgetting that list indexes start at 0. fruits[1] refers to the second element, so the mismatch between "1st = fruits[0]" often causes bugs. Accessing an index that doesn't exist raises an IndexError, so watch out for that too.

In real development, any collection of records — a product catalog, a list of user comments — is almost always handled as a list. Data returned from a database or an API is frequently list-shaped as well, so getting comfortable with lists is genuinely foundational to Python programming.

Python
OUTPUT

💡 The Python engine may take a few seconds to load the first time you run code.

Ad space (banner)
Ad space (in-article)