DEV Community

Cover image for Python Lists (one of the first things that actually made sense)
still-purrfect
still-purrfect

Posted on

Python Lists (one of the first things that actually made sense)

When I started learning Python, lists were one of the first things that actually clicked for me. They’re simple, but also really useful.
Before this, I was learning about variables and how to store single values. Lists felt like the next step storing multiple values in one place.
👉 If you missed it, you can read about variables here: [https://dev.to/stillpurrfect/python-variables-the-tiny-containers-that-run-everything-you-see-in-code-4dke]

What is a list?
A list is just a way to store multiple values in one place.

numbers = [1, 2, 3]

Enter fullscreen mode Exit fullscreen mode

That’s it.
Instead of creating many variables, you just put everything inside one list.

Why I like lists
The best part about lists is that you can change them.
You can add things:

numbers = [1, 2, 3]
numbers.append(4)
Enter fullscreen mode Exit fullscreen mode

You can remove things:

numbers.remove(2)
Enter fullscreen mode Exit fullscreen mode

You can even change values:

numbers[0] = 10
Enter fullscreen mode Exit fullscreen mode

This made lists feel very flexible compared to other things I’ve learned so far.
A simple example
Let’s say I want to store names:

names = ["Maryanne", "John", "Aisha"]
Enter fullscreen mode Exit fullscreen mode

If I want to get the first name:

print(names[0])
Enter fullscreen mode Exit fullscreen mode

At first, the [0] was confusing, but I’m getting used to it now.

What I’m starting to notice
Lists are good when your data might change.
Like:

  • Adding new items
  • Removing items
  • Updating values That’s probably why they’re used a lot.

My takeaway (so far)
Lists are:

  • Easy to understand
  • Easy to use
  • Very flexible I feel like they’re one of those things you’ll keep using over and over again.

Final thought
I’m still learning, but lists made Python feel a bit less scary for me.
If you’re just starting out, this is one of those topics that’s worth practicing a lot.

If you’re learning Python too, what was the first concept that actually made sense to you?
I also explored tuples (which confused me at first 😅):
👉 Read it here: [https://dev.to/stillpurrfect/tuples-in-python-something-i-almost-ignored-58cm]

Top comments (0)