List in Python Notes – Class 11 CS (083)
Get High-Scoring Revision Notes with Easy Concept Clarity for Lists in Python, specially designed for Class 11 Computer Science students. These List in Python notes are completely aligned with the latest CBSE syllabus and present every concept in a clear, concise, and easy-to-understand manner.
From basic list operations to important methods and applications, each topic is explained precisely with examples to help students build a strong foundation. Perfect for quick revision, concept reinforcement, and confident exam preparation.
- A list is an ordered collection of elements in Python.
- Lists are mutable, which means their elements can be changed after creation.
- A list can store different types of data together such as integers, float values, strings, tuples, and even another list.
- Lists are written inside square brackets [ ] and elements are separated using commas.
- List indexing starts from 0, just like strings.
Syntax of List
list_name = [element1, element2, element3]
Examples of Lists
List of Prime Numbers
# list1 stores prime numbers
list1 = [2, 3, 5, 7, 11, 13]
print(list1)
Output
[2, 3, 5, 7, 11, 13]
List of Fruits
# list2 stores fruit names
list2 = [‘Apple’, ‘Mango’, ‘Banana’, ‘Orange’]
print(list2)
Output
[‘Apple’, ‘Mango’, ‘Banana’, ‘Orange’]
List with Mixed Data Types
# list3 stores different data types
list3 = [101, 85.6, “Python”]
print(list3)
Output
[101, 85.6, ‘Python’]
Nested List
A list containing another list is called a nested list.
# list4 is a nested list
list4 = [[‘Riya’, 85],
[‘Aman’, 90],
[‘Karan’, 88]]
print(list4)
Output
[[‘Riya’, 85], [‘Aman’, 90], [‘Karan’, 88]]
Accessing Elements in a List
Elements of a list are accessed using index numbers.
Indexing in a list starts from 0, just like strings.
- Positive indexing starts from the left side.
- Negative indexing starts from the right side.
Examples of Accessing List Elements
# initializes a list
marks = [78, 85, 92, 88, 76, 95]
# returns first element
print(marks[0])
# returns fourth element
print(marks[3])
# expression resulting in an integer index
print(marks[2 + 1])
# returns first element from the right
print(marks[-1])
# length of the list is assigned to n
n = len(marks)
print(n)
# returns last element
print(marks[n – 1])
# returns first element
print(marks[-n])
# index value is greater than list length
print(marks[10])
Output
78
88
88
95
6
95
78
IndexError: list index out of range
List Operations
Concatenation of Lists
- Python allows us to join two or more lists using the concatenation operator (+).
- The elements of the first list are followed by the elements of the second list to form a new list.
Example 1: Concatenating Lists of Subjects
# list1 stores science subjects
list1 = [‘Physics’, ‘Chemistry’, ‘Biology’]
# list2 stores computer subjects
list2 = [‘Python’, ‘AI’, ‘Data Science’]
# concatenating two lists
print(list1 + list2)
Output
[‘Physics’, ‘Chemistry’, ‘Biology’, ‘Python’, ‘AI’, ‘Data Science’]
TypeError in Concatenation
- The + operator works only with lists.
- If we try to concatenate a list with another data type, Python generates a TypeError.
list1 = [10, 20, 30]
num = 50
print(list1 + num)
Output
TypeError: can only concatenate list (not “int”) to list
Repetition
- Python allows us to repeat a list using the repetition operator (*).
- It creates multiple copies of the same list elements.
Example: Repetition of a List
# list1 contains a single element
list1 = [‘Hello’]
# repeating the list 4 times
print(list1 * 4)
Output
[‘Hello’, ‘Hello’, ‘Hello’, ‘Hello’]
Membership Operators
Membership operators are used to check whether an element is present in a list or not.
- in → returns True if element is present
- not in → returns True if element is not presentTop of Form
Example: in and not in Operators
list1 = [‘Red’, ‘Green’, ‘Blue’]
# in operator
print(‘Green’ in list1)
print(‘Cyan’ in list1)
# not in operator
print(‘Cyan’ not in list1)
print(‘Green’ not in list1)
Output
True
False
True
False
Slicing in Lists
- Like strings, slicing can also be applied to lists.
- Slicing is used to extract a part (sublist) from a list using index range.
Syntax:
list[start : end : step]
- start → starting index (included)
- end → ending index (excluded)
- step → gap between elements
Example: Slicing Operations
list1 = [‘Red’, ‘Green’, ‘Blue’, ‘Cyan’, ‘Magenta’, ‘Yellow’, ‘Black’]
# slicing from index 2 to 5
print(list1[2:6])
# end index out of range
print(list1[2:20])
# start index greater than end index
print(list1[7:2])
# first index missing
print(list1[:5])
# step size 2
print(list1[0:6:2])
# negative indexing
print(list1[-6:-2])
# entire list with step 2
print(list1[::2])
# reverse list using negative step
print(list1[::-1])
Output
[‘Blue’, ‘Cyan’, ‘Magenta’, ‘Yellow’]
[‘Blue’, ‘Cyan’, ‘Magenta’, ‘Yellow’, ‘Black’]
[]
[‘Red’, ‘Green’, ‘Blue’, ‘Cyan’, ‘Magenta’]
[‘Red’, ‘Blue’, ‘Magenta’]
[‘Green’, ‘Blue’, ‘Cyan’, ‘Magenta’]
[‘Red’, ‘Blue’, ‘Magenta’, ‘Black’]
[‘Black’, ‘Yellow’, ‘Magenta’, ‘Cyan’, ‘Blue’, ‘Green’, ‘Red’]
Traversing a List
List traversal means accessing each element of a list one by one.
We can traverse a list using:
- for loop
- while loop
List Traversal Using for Loop
In a for loop, each element of the list is accessed directly.
Example
list1 = [‘Red’, ‘Green’, ‘Blue’, ‘Yellow’, ‘Black’]
for item in list1:
print(item)
Output
Red
Green
Blue
Yellow
Black
Traversal Using range() and len()
We can also use index-based traversal using range() and len().
Example
list1 = [‘Red’, ‘Green’, ‘Blue’, ‘Yellow’, ‘Black’]
for i in range(len(list1)):
print(list1[i])
Output
Red
Green
Blue
Yellow
Black
List Traversal Using while Loop
In a while loop, indexing is used to access list elements.
Example
list1 = [‘Red’, ‘Green’, ‘Blue’, ‘Yellow’, ‘Black’]
i = 0
while i < len(list1):
print(list1[i])
i += 1
Output
Red
Green
Blue
Yellow
Black
List Methods and Built-in Functions
Python provides several built-in functions and methods to perform operations on lists.
| Method / Function | Description | Example |
| len() | Returns the total number of elements in the list. | list1 = [“CBSE”, “Solutions”, “Python”] print(len(list1)) Output: 3 |
| list() | Creates a list. If no argument is given, creates an empty list. | list1 = list() print(list1) Output: [] |
| append() | Adds a single element at the end of the list. | list1 = [“CBSE”, “Solutions”] list1.append(“Notes”) print(list1) Output: [‘CBSE’, ‘Solutions’, ‘Notes’] |
| extend() | Adds all elements of another list to the end. | list1 = [“CBSE”] list1.extend([“Solutions”, “Python”]) print(list1) Output: [‘CBSE’, ‘Solutions’, ‘Python’] |
| insert() | Inserts an element at a specific position. | list1 = [“CBSE”, “Python”] list1.insert(1, “Solutions”) print(list1) Output: [‘CBSE’, ‘Solutions’, ‘Python’] |
| count() | Returns number of occurrences of an element. | list1 = [“CBSE”, “Python”, “CBSE”] print(list1.count(“CBSE”)) Output: 2 |
| index() | Returns index of first occurrence of an element. | list1 = [“CBSE”, “Solutions”, “Python”] print(list1.index(“Python”)) Output: 2 |
| remove() | Removes first occurrence of an element. | list1 = [“CBSE”, “Solutions”, “Python”, “Solutions”] list1.remove(“Solutions”) print(list1) Output: [‘CBSE’, ‘Python’, ‘Solutions’] |
| pop() | Removes and returns element at given index (last if not specified). | list1 = [“CBSE”, “Solutions”, “Python”] print(list1.pop()) print(list1) Output: Python [‘CBSE’, ‘Solutions’] |
| reverse() | Reverses the order of elements in the list. | list1 = [“CBSE”, “Solutions”, “Python”] list1.reverse() print(list1) Output: [‘Python’, ‘Solutions’, ‘CBSE’] |
| sort() | Sorts the list in ascending order (in-place). | list1 = [“Python”, “CBSE”, “AI”] list1.sort() print(list1) Output: [‘AI’, ‘CBSE’, ‘Python’] |
| sorted() | Returns a new sorted list without changing original list. | list1 = [“Python”, “CBSE”, “AI”] print(sorted(list1)) Output: [‘AI’, ‘CBSE’, ‘Python’] |
| min() | Returns smallest element in the list. | list1 = [10, 20, 5] print(min(list1)) Output: 5 |
| max() | Returns largest element in the list. | list1 = [10, 20, 5] print(max(list1)) Output: 20 |
| sum() | Returns sum of all elements in the list. | list1 = [10, 20, 5] print(sum(list1)) Output: 35 |
Programs Using Lists in Python
Find Maximum, Minimum and Mean of Numbers in a List
Program
list1 = [10, 20, 30, 40, 50]
# Maximum value
print(“Maximum :”, max(list1))
# Minimum value
print(“Minimum :”, min(list1))
# Mean (Average)
mean = sum(list1) / len(list1)
print(“Mean :”, mean)
Output
Maximum : 50
Minimum : 10
Mean : 30.0
Linear Search in a List
Program
list1 = [10, 20, 30, 40, 50]
key = 30
found = False
for i in range(len(list1)):
if list1[i] == key:
print(“Element found at index”, i)
found = True
break
if not found:
print(“Element not found”)
Output
Element found at index 2
Count Frequency of Elements in a List
Program
list1 = [10, 20, 10, 30, 20, 10]
visited = []
for item in list1:
if item not in visited:
print(item, “occurs”, list1.count(item), “times”)
visited.append(item)
Output
10 occurs 3 times
20 occurs 2 times
30 occurs 1 times