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]
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
Accessing list elements using an index:
print(numbers[0]) # Output: 10
print(numbers[1]) # Output: 20
Accessing list elements using an -ve index:
print(numbers[-1]) # Output: 30
print(numbers[-2]) # Output: 10
Top comments (0)