Python Lists – Your First Step into Storing and Managing Data

Hey there! If you've mastered strings and are ready for your next Python milestone — welcome! Today, we're diving into lists, which are like super-smart containers for your data. Instead of juggling a bunch of separate variables, you can group items together neatly and work with them easily.

When you start programming, you’ll quickly realize you need a way to store more than one value in a single variable.
For example: instead of creating 10 separate variables for 10 fruits, you can just use a list.

In Python, lists are like containers where you can store multiple items — numbers, strings, or even other lists — all in one place. And the best part? Lists are mutable — which means you can change them!


1. Creating Your First List

You can make an empty list—or load it right up with a few items:

# Empty list
my_list = []

# A list with some items
fruits = ["apple", "banana", "cherry"]

# Mixed kinds of data side by side
mixed = [1, "hello", 3.14, True]

2. Seeing Inside Your List (Indexing)

Just like books on a shelf, every item has a spot—starting from 0 (just like how we saw in the strings article.)

fruits = ["apple", "banana", "cherry"]

print(fruits[0])   # apple
print(fruits[1])   # banana
print(fruits[-1])  # cherry

That -1 grabs you the last item—handy when you don’t know how many are inside.


3. Changing Things Up

Unlike strings, you can change lists. Let’s swap one fruit for another:

fruits = ["apple", "banana", "cherry"]
fruits[1] = "mango"
print(fruits)  # ['apple', 'mango', 'cherry']

4. Adding More Goodies

Want to expand your list? You’ve got options:

fruits = ["apple", "banana", "cherry"]
fruits.append("orange")         # Adds at the end
fruits.insert(1, "grape")       # Places it in position 1
fruits.extend(["kiwi", "melon"])  # Adds several at once
print(fruits) # ['apple', 'grape', 'banana', 'cherry', 'orange', 'kiwi', 'melon']

5. Removing Items—With Care

Lists can lose items too—pick whichever method suits your need:

fruits = ["apple", "grape", "banana", "cherry", "orange", "kiwi", "melon"]
fruits.remove("melon")  # Remove by value
fruits.pop(2)           # Remove by position
del fruits[0]           # Delete specific spot
print(fruits)           # ['grape', 'cherry', 'orange', 'kiwi']
fruits.clear()          # Empty the whole list
print(fruits)           # []

6. Seeing a Slice of the List (Slicing)

Want part of your list? Slicing gives you that:

It will return the range of values that are mentioned as indices in the square braces.

And while mentioning the index value the left side value of colon is used as the starting position and the right side value of colon is used as the stopping index and this index will not be considered.

For example if we give as list1[2:5] then it will return the list1 values that are present in the indexes 2,3,4

numbers = [0, 1, 2, 3, 4, 5]
print(numbers[1:4])   # [1, 2, 3]
print(numbers[:3])    # [0, 1, 2]
print(numbers[::2])   # [0, 2, 4]

7. Handy List Methods

These are daily helpers worth knowing:

numbers = [3, 1, 4, 1, 5, 9]

numbers.sort()             # Order the list
numbers.reverse()          # Flip it backward
print(numbers.index(4))    # Find where 4 is
print(numbers.count(1))    # How many 1s?
copy_list = numbers.copy() # Make a safe copy

Conclusion

Lists are one of the most powerful and flexible tools in Python.
They let you store, modify, and organize data with ease — and you’ll be using them in almost every Python program you write.

Tip: Practice by making small programs that store multiple items in a list, like a grocery list or a favorite movies list.

0
Subscribe to my newsletter

Read articles from Tammana Prajitha directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Tammana Prajitha
Tammana Prajitha