DEV Community

Cover image for 🔥Building Array Data Structure in python
Ritik Sharma
Ritik Sharma

Posted on • Edited on

🔥Building Array Data Structure in python

What is list?

  • A list in Python is a built-in(comes with python itself) data structure that stores a collection of values of any data type.
  • Lists are ordered, mutable (i.e., can be changed), and can contain elements of different data types.

for example:-

grocery = ["Sugar:1kg", "Tooth paste : 1", "masala:1kg"]
person = ["Ritik", "patna", 8, 56.32]
Enter fullscreen mode Exit fullscreen mode

Here are some common operations and examples of how to use lists in Python:

How to use?

Creating a list:

numbers = [10, 20, 30]
# index =  0   1    2
Enter fullscreen mode Exit fullscreen mode

Accessing list elements using an index:

print(numbers[0]) # Output: 10
print(numbers[1]) # Output: 20
Enter fullscreen mode Exit fullscreen mode

Accessing list elements using an -ve index:

print(numbers[-1]) # Output: 30
print(numbers[-2]) # Output: 10
Enter fullscreen mode Exit fullscreen mode

Top comments (0)