DEV Community

Cover image for Lists in Python
datatoinfinity
datatoinfinity

Posted on

Lists in Python

A list is data structure in python that is mutable, or changeable, ordered sequence of element.

Now break it down this definition. Let's start with why list is a data structure.

Data Structure: A data structure is a way to store, organize, and manage data so it can be used efficiently.

When we say list is data structure its means:

A list is one of the built-in tools Python provides to hold a collection of items in an ordered and changeable way.

Now understand what it means mutable and changeable.
well we can use it alternatively as in for developer it is mutable and for beginner it can changeable.

list1=[1,2,3]
list1[0]=4
print(list1)
Output:
[4, 2, 3]

Lets take an example of ordered sequence

A list being ordered means the position of each item is fixed, and you can rely on it to stay that way—unless you change it.

list1=['cherry','tomato','brinjal']
print(list1[0])
Output:
cherry

Position means index of an item like
cherry->index 0
tomato->index 1
brinjal->index 2

Top comments (0)