Python Lists | Creating, Initializing, Traversing, Manipulating Lists and List Methods | Complete Notes | CBSE Class 11 Informatics Practices (2026–27)
Class 11 · Informatics Practices
Python Lists | Creating, Initializing, Traversing, Manipulating Lists and List Methods
In Python, a variable can store only one value at a time. However, in many real-life situations, we need to store multiple related values together. For example, the marks of all students in a class, the names of books in a library, or the prices of different products cannot be conveniently stored in separate variables. Python solves this problem by providing the List data type.
A list is one of the most widely used data structures in Python. It allows multiple values of different data types to be stored in a single variable. Lists are ordered, mutable, and can contain duplicate values, making them extremely useful in real-world applications.
Learning Outcomes
After studying this chapter, you will be able to:
- Understand the concept of lists.
- Create and initialize lists.
- Access list elements using indexing.
- Traverse a list using loops.
- Modify list elements.
- Perform basic list operations.
- Use important list methods.
What is a List?
A list is an ordered collection of elements enclosed within square brackets [ ]. Each element is separated by a comma.
Example
marks = [78, 85, 92, 67, 89]
In the above example, marks is a list containing five integer values.
Why Do We Need Lists?
Without a List:
student1 = 82
student2 = 91
student3 = 76
student4 = 88
student5 = 95
Using a List:
marks = [82, 91, 76, 88, 95]
Using a list reduces the number of variables, simplifies programming, and makes data processing much easier.
Characteristics of Lists
- Lists are ordered collections.
- Lists are mutable, which means their elements can be modified.
- Lists can contain duplicate values.
- Lists can store elements of different data types.
- Lists can grow or shrink dynamically.
- Lists support indexing and slicing.
Creating a List
A list is created by placing elements inside square brackets separated by commas.
Syntax
list_name = [element1, element2, element3]
Examples
numbers = [10, 20, 30, 40]
cities = ["Jaipur", "Delhi", "Mumbai"]
mixed = [10, "Python", 95.5, True]
Creating an Empty List
students = []
An empty list contains no elements and can be populated later.
Using the list() Function
The list() function creates a list from another iterable object such as a string, tuple, or range.
Example 1
letters = list("Python")
print(letters)
Output
['P', 'y', 't', 'h', 'o', 'n']
Example 2
numbers = list(range(1,6))
print(numbers)
Output
[1, 2, 3, 4, 5]
Initializing a List
Initializing means assigning values to a list at the time of its creation.
Example
subjects = ["English", "Physics", "Chemistry", "Mathematics"]
Accessing List Elements
Each element in a list is identified by its position, known as its index. Python uses zero-based indexing.
Example
fruits = ["Apple", "Banana", "Mango", "Orange"]
print(fruits[0])
print(fruits[2])
Output
Apple
Mango
Positive Indexing
| Index | 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|---|
| List | Python | Java | C++ | SQL | HTML |
Negative Indexing
Negative indexing starts from the end of the list.
| Index | -5 | -4 | -3 | -2 | -1 |
|---|---|---|---|---|---|
| List | Python | Java | C++ | SQL | HTML |
Example
languages = ["Python", "Java", "C++", "SQL", "HTML"]
print(languages[-1])
print(languages[-3])
Output
HTML
C++
Traversing a List
Traversing means accessing each element of a list one by one.
Traversing Using a for Loop
subjects = ["English", "Physics", "Chemistry", "Biology"]
for subject in subjects:
print(subject)
Output
English
Physics
Chemistry
Biology
Traversing Using Index Values
marks = [82, 91, 76, 88]
for i in range(len(marks)):
print("Index:", i, "Value:", marks[i])
Output
Index: 0 Value: 82
Index: 1 Value: 91
Index: 2 Value: 76
Index: 3 Value: 88
Finding the Length of a List
The len() function returns the total number of elements present in a list.
Syntax
len(list_name)
Example
students = ["Aarav", "Diya", "Kabir", "Riya"]
print(len(students))
Output
4
Real-Life Application
A school stores the marks of all students in a list. Using loops, the teacher can display every student's marks, calculate totals, find the highest score, or identify students who need additional support.
Updating List Elements
Since lists are mutable, their elements can be modified after the list has been created.
Syntax
list_name[index] = new_value
Example
marks = [75, 82, 90, 88]
marks[1] = 85
print(marks)
Output
[75, 85, 90, 88]
Adding Elements to a List
Python provides different methods to add new elements to a list.
The append() Method
The append() method adds a single element at the end of a list.
Syntax
list_name.append(element)
Example
subjects = ["English", "Physics"]
subjects.append("Chemistry")
print(subjects)
Output
['English', 'Physics', 'Chemistry']
The insert() Method
The insert() method inserts an element at a specified position.
Syntax
list_name.insert(index, element)
Example
cities = ["Jaipur", "Delhi", "Mumbai"]
cities.insert(1, "Kota")
print(cities)
Output
['Jaipur', 'Kota', 'Delhi', 'Mumbai']
Searching in a List
The count() Method
The count() method returns the number of times an element appears in a list.
Syntax
list_name.count(element)
Example
numbers = [10, 20, 10, 30, 10]
print(numbers.count(10))
Output
3
The index() Method
The index() method returns the position of the first occurrence of the specified element.
Syntax
list_name.index(element)
Example
colors = ["Red", "Blue", "Green"]
print(colors.index("Blue"))
Output
1
Removing Elements from a List
Elements can be removed using the remove() and pop() methods.
The remove() Method
The remove() method removes the first occurrence of the specified element from the list.
Syntax
list_name.remove(element)
Example
fruits = ["Apple", "Mango", "Banana"]
fruits.remove("Mango")
print(fruits)
Output
['Apple', 'Banana']
The pop() Method
The pop() method removes and returns the element at the specified index. If no index is given, it removes the last element.
Syntax
list_name.pop(index)
Example 1
numbers = [10, 20, 30, 40]
numbers.pop()
print(numbers)
Output
[10, 20, 30]
Example 2
numbers = [10, 20, 30, 40]
numbers.pop(1)
print(numbers)
Output
[10, 30, 40]
The reverse() Method
The reverse() method reverses the order of elements in the list.
Syntax
list_name.reverse()
Example
numbers = [1, 2, 3, 4]
numbers.reverse()
print(numbers)
Output
[4, 3, 2, 1]
The sort() Method
The sort() method arranges the elements of a list in ascending order by default.
Syntax
list_name.sort()
Example
marks = [82, 75, 91, 68]
marks.sort()
print(marks)
Output
[68, 75, 82, 91]
Descending Order
marks = [82, 75, 91, 68]
marks.sort(reverse=True)
print(marks)
Output
[91, 82, 75, 68]
The min() Function
The min() function returns the smallest element in the list.
Example
marks = [82, 75, 91, 68]
print(min(marks))
Output
68
The max() Function
The max() function returns the largest element in the list.
Example
marks = [82, 75, 91, 68]
print(max(marks))
Output
91
The sum() Function
The sum() function returns the sum of all numeric elements in a list.
Example
marks = [82, 75, 91, 68]
print(sum(marks))
Output
316
Comparison of Important List Methods
| Method / Function | Purpose |
|---|---|
| append() | Adds an element at the end of the list. |
| insert() | Inserts an element at a specified position. |
| count() | Counts the occurrences of an element. |
| index() | Returns the index of the first occurrence of an element. |
| remove() | Removes the specified element. |
| pop() | Removes an element using its index. |
| reverse() | Reverses the order of elements. |
| sort() | Sorts the list. |
| len() | Returns the number of elements. |
| min() | Returns the smallest element. |
| max() | Returns the largest element. |
| sum() | Returns the total of numeric elements. |
List Manipulation
Apart from adding or removing elements, Python provides several operations to manipulate lists. These operations make it easy to combine, repeat, search, and extract elements from lists.
List Concatenation (+)
The + operator is used to join two or more lists. This operation is called list concatenation.
Example
list1 = [10, 20, 30]
list2 = [40, 50]
result = list1 + list2
print(result)
Output
[10, 20, 30, 40, 50]
List Repetition (*)
The * operator repeats the elements of a list a specified number of times.
Example
numbers = [1, 2]
print(numbers * 3)
Output
[1, 2, 1, 2, 1, 2]
Membership Operators
The in and not in operators are used to check whether an element exists in a list.
Example
subjects = ["English", "Physics", "Chemistry"]
print("Physics" in subjects)
print("Maths" in subjects)
print("Maths" not in subjects)
Output
True
False
True
List Slicing
List slicing extracts a portion of a list using the slicing operator (:).
Syntax
list_name[start:stop:step]
Example
numbers = [10,20,30,40,50,60]
print(numbers[1:4])
print(numbers[:3])
print(numbers[2:])
print(numbers[::2])
Output
[20, 30, 40]
[10, 20, 30]
[30, 40, 50, 60]
[10, 30, 50]
Real-Life Applications of Lists
| Application | Use of List |
|---|---|
| School ERP | Store marks of students. |
| Hospital Management | Maintain patient records. |
| Online Shopping | Store products in a shopping cart. |
| Library Management | Maintain book titles. |
| Cricket Scoreboard | Store players' scores. |
Solved Program 1: Find the Largest Number
numbers = [45, 82, 19, 96, 54]
print(max(numbers))
Output
96
Solved Program 2: Find the Smallest Number
numbers = [45, 82, 19, 96, 54]
print(min(numbers))
Output
19
Solved Program 3: Calculate Total Marks
marks = [85, 78, 92, 88, 76]
print(sum(marks))
Output
419
Solved Program 4: Display All Student Names
students = ["Aarav", "Diya", "Kabir", "Riya"]
for name in students:
print(name)
Output
Aarav
Diya
Kabir
Riya
Solved Program 5: Count Occurrences
numbers = [10,20,10,30,10,40]
print(numbers.count(10))
Output
3
Common Errors
| Mistake | Correct Practice |
|---|---|
| Using an invalid index. | Ensure the index is within the valid range. |
| Trying to remove a value that does not exist. | Check whether the element is present before using remove(). |
| Confusing append() and insert(). | append() adds at the end, while insert() adds at a specified position. |
| Using pop() without checking the list size. | Ensure the list is not empty before removing an element. |
| Assuming sort() creates a new list. | sort() modifies the existing list. |
Interview Corner
Q. Why are lists called mutable objects?
Answer: Lists are called mutable because their elements can be modified, added, or removed after the list has been created without creating a new list.
Competency-Based Questions
- A teacher stores the marks of all students in a list. Which Python function should be used to calculate the total marks of the class?
- A shopping application stores products in a list. Which method should be used to add a new product at the end of the list?
- A school ERP needs to remove a student who has left the school. Which list method is appropriate?
- A librarian wants to know whether the book "Python Basics" exists in the list of books. Which operator should be used?
Multiple Choice Questions
- The elements of a list are enclosed within:
- (a) ( )
- (b) { }
- (c) [ ]
- (d) < >
- Which method adds an element at the end of a list?
- (a) insert()
- (b) append()
- (c) remove()
- (d) pop()
- Which function returns the largest value in a list?
- (a) len()
- (b) sum()
- (c) max()
- (d) reverse()
- Which method removes and returns an element by index?
- (a) remove()
- (b) pop()
- (c) delete()
- (d) clear()
Quick Revision
| Concept | Remember |
|---|---|
| List | Ordered, mutable collection. |
| append() | Adds an element at the end. |
| insert() | Adds an element at a specified position. |
| remove() | Removes a specified element. |
| pop() | Removes an element by index. |
| count() | Counts occurrences of an element. |
| index() | Returns the first index of an element. |
| reverse() | Reverses the list. |
| sort() | Sorts the list. |
| min() | Returns the smallest element. |
| max() | Returns the largest element. |
| sum() | Returns the sum of numeric elements. |
Important Points to Remember
- Lists are ordered, mutable collections.
- Lists can store duplicate values.
- Lists can contain elements of different data types.
- Indexing starts from 0.
- Negative indexing starts from -1.
- append() adds an element at the end.
- insert() adds an element at a specified position.
- remove() removes a value, whereas pop() removes an element using its index.
- sort() modifies the original list.
- len(), min(), max(), and sum() are built-in functions used with lists.
CBSE Exam Tips
- Practice all important list methods with examples.
- Remember the difference between append(), insert(), remove(), and pop().
- Understand positive and negative indexing.
- Learn how to traverse a list using a for loop.
- Practice questions involving sort(), reverse(), min(), max(), and sum().
- Be able to trace list manipulation programs to determine the output.
Summary
A list is one of the most versatile and widely used data structures in Python. It allows multiple values to be stored, accessed, modified, and processed efficiently. Python provides powerful built-in functions and methods such as append(), insert(), remove(), pop(), sort(), reverse(), len(), min(), max(), and sum(), making list manipulation simple and efficient. A thorough understanding of lists is essential for solving real-world programming problems and forms the foundation for learning advanced data structures in Python.