A list is a collection of items in a partcular order. You can make a list that includes letters of alphabet, the digits from 0 to 9 or the names of all people in your family. You can put anything you want to into in your list. A list usually containes more than one elements, it is good idea to make the name of your list plural such as letters, digits, names.

Do it
Indexing List Items
List items are indexed. First item is [0]. Then incresed accordingly.
[0] [1] [2] [3] [4] [5] [6] [7] — [N]
Squre Brackets
In python square bracket indicates a list and individual elements are seperated by comas.
# A list of animals using square brackets and comma-separated elements
animals = ["lion", "tiger", "elephant", "zebra", "giraffe"]
# Display the list
print("Animal List:", animals)
Maintain Order
In Python, a list is considered ordered, which means that each item retains a specific position, and that sequence remains unchanged unless deliberately modified. When a new element is added to the list, it is automatically inserted at the end, maintaining the original arrangement of items. This ensures that the order in which elements are added is preserved throughout the list’s usage.
Do it
Changing List Items
In Python, a list is changeable, also known as mutable. This means you can modify the contents of the list even after it has been created. You can change the value of an existing item, add new items to the list, or remove items as needed. This flexibility makes lists very useful for handling collections of data that may need to be updated over time.
fruits = ["apple", "banana", "mango"]
# Changing an item
fruits[1] = "orange"
# Adding a new item
fruits.append("grape")
# Removing an item
fruits.remove("apple")
print(fruits)
Do it
Allowing Duplicate
Since lists in Python are indexed, each item is stored at a specific position identified by an index number. This allows lists to contain duplicate values, meaning the same item can appear multiple times at different positions. The index helps to distinguish between these repeated elements, even if their values are identical. This feature is useful when the occurrence of repeated data needs to be preserved or counted.
# List with duplicate values
numbers = [10, 20, 10, 30, 20, 10]
# Display the list
print("List with Duplicates:", numbers)
# Accessing by index
print("First Item:", numbers[0])
print("Third Item (Duplicate of First):", numbers[2])
Do it
Length of List
To find out how many items are in a list, you can use Python’s built-in len() function. This function returns the total number of elements present in the list, regardless of their values or types. It’s a simple and efficient way to measure the length of a list, which can be especially useful when processing or looping through data.
# List of cities
cities = ["Dhaka", "Chittagong", "Khulna", "Rajshahi", "Sylhet"]
# Use len() to get the number of items
total_cities = len(cities)
# Display the result
print("Total Number of Cities:", total_cities)
Do it
List Items – Data Types
In Python, a list can hold items of any data type, including strings, integers, floats, booleans, and even other lists. Unlike some programming languages that require all elements in a list to be of the same type, Python allows a mix of different data types within the same list. This flexibility makes lists very powerful for storing collections of related but varied information. Each item retains its original data type, allowing for diverse operations within a single list.
# A list with mixed data types
mixed_list = ["apple", 42, 3.14, True, [1, 2, 3]]
# Display the list
print("Mixed Data Type List:", mixed_list)
Do it
Various items of List
A list in Python can contain multiple data types, allowing you to store a mix of values such as strings, integers, floats, booleans, and even other lists within the same structure. This means a single list can hold varied forms of data without any restrictions on type uniformity. This flexibility makes lists highly adaptable for real-world applications, where different kinds of information often need to be grouped together and processed as a unit.
# List with different data types
my_list = ["Hello", 100, 45.6, False, [1, 2, 3]]
# Display the list
print("List with Mixed Data Types:", my_list)
Do it
List are Objects
From Python’s perspective, lists are objects that belong to the built-in data type called 'list'. This means that every list you create is actually an instance of the list class, which comes with a variety of built-in methods and properties. These methods allow you to perform operations like adding, removing, sorting, or counting elements. Since lists are objects, they follow object-oriented principles and are part of Python’s powerful and flexible type system.
# Define a list
my_list = [10, 20, 30]
# Check the type of the variable
print("Data Type of my_list:", type(my_list))
Do it
List Constructor
In Python, you can also create a list using the built-in list() constructor instead of using square brackets. This approach is especially useful when converting other iterable data types—such as strings, tuples, or sets—into lists. The list() constructor takes an iterable as an argument and returns a new list containing the elements of that iterable. It offers flexibility in situations where list creation depends on dynamic data or type conversion.
Do it
Accessing Elements of a List
Lists in Python are an ordered collection, which means the elements are stored in a specific sequence, and each item has a defined position, known as an index. Because of this order, you can easily access any element in the list by referring to its index number. Indexing starts from 0 for the first item, 1 for the second, and so on. This allows you to retrieve, update, or manipulate individual elements directly based on their position in the list.
# Define a list of animals
animals = ["cat", "dog", "elephant", "tiger", "lion"]
# Access elements using index
print("First Animal:", animals[0]) # Index 0
print("Third Animal:", animals[2]) # Index 2
print("Last Animal:", animals[-1]) # Negative index
Do it
Indexing Position
In Python, list indexing starts at 0, meaning the first item in a list is accessed using index 0, not 1. This is known as zero-based indexing. So, the second item is at index 1, the third at index 2, and so on. Python also supports negative indexing, where the last item of a list is accessed using index -1, the second last with -2, and so forth. This feature allows you to conveniently work with both the beginning and end of a list.
Do it
# Define a list of fruits
fruits = ["apple", "banana", "cherry", "mango", "orange"]
# Accessing items using zero-based indexing
print("First Fruit (index 0):", fruits[0])
print("Second Fruit (index 1):", fruits[1])
# Accessing the last item using negative indexing
print("Last Fruit (index -1):", fruits[-1])
print("Second Last Fruit (index -2):", fruits[-2])
Do it
Using Individual Value from a List
In Python, individual values from a list can be used just like any other variable. Once you access an item using its index, you can store it in a new variable, use it in calculations, print it, or pass it to a function. This makes lists very practical for working with sets of data where each item may need to be processed or used independently.
# Define a list of numbers
numbers = [5, 10, 15, 20]
# Use individual list items like variables
a = numbers[0]
b = numbers[2]
sum_result = a + b
print("First Number:", a)
print("Third Number:", b)
print("Sum of First and Third:", sum_result)
Do it
Modifying Elements of a List
In Python, the elements of a list can be modified after the list has been created. Since lists are mutable, you can change the value of any item by accessing it through its index and assigning a new value. This allows for flexible data manipulation, making lists ideal for situations where the data may need to be updated or changed over time.
# Original list
colors = ["red", "blue", "green"]
# Modify the second element (index 1)
colors[1] = "yellow"
# Display the modified list
print("Updated Colors List:", colors)
Do it
Appending Elements to End of a List
In Python, you can append elements to the end of a list using the built-in append() method. This method adds a single item to the end of the existing list without affecting the current elements. It’s one of the most common ways to expand a list dynamically, especially when collecting or building data over time.
# Create an initial list of numbers
numbers = [1, 2, 3]
# Append a new number to the end
numbers.append(4)
# Append another number
numbers.append(5)
# Display the updated list
print("Updated List:", numbers)