Skip to content
← Computer Science

Computer Science · Class 11 Optional

Ch 9Lists — Class 11 Computer Science, concept-first.

A list is Python's workhorse container: an ordered sequence of values that is mutable, meaning its contents can be changed after it is created. A list is made up of one or more elements, and — unlike a string, which can hold only characters — a list may freely mix elements of different data types: integers, floats, str…

26

Q&A

10

Concepts

Not available

Exam weightage

Start learning — read this chapter →

Key concepts

Hover a concept to preview it and jump to its most relevant Q&A.

Chapter contents

The NCERT structure, section by section. Open a section to see its questions, then read the concept-first solution.

9.1

Introduction to List

A list is Python's workhorse container: an ordered sequence of values that is mutable, meaning its contents can be changed after it is created.

9.1.1

Accessing Elements in a List

Individual elements of a list are picked out exactly the way characters are picked out of a string: write the list's name followed by the element's index in square brackets.

9.1.2

Lists are Mutable

Lists in Python are mutable: the contents of a list can be changed after the list has been created. This is the single most important property separating a list from a string — a string, once built, c…

9.2

List Operations

The list data type lets you manipulate its contents through a family of operations, each covered in its own sub-section:

9.2.1

Concatenation

Python joins two or more lists using the concatenation operator, written with the symbol +. The result is a single new list containing the elements of the first list followed by the elements of the se…

9.2.2

Repetition

Python can replicate a list using the repetition operator, written with the symbol . Multiplying a list by an integer n produces a new list in which the original elements are repeated n times over, in…

9.2.3

Membership

Just as with strings, Python provides membership operators to ask whether a value occurs in a list. There are two of them, and each returns a Boolean result — True or False.

9.2.4

Slicing

The slicing operation that extracts substrings from a string applies to lists as well: list[start:stop] returns a new list containing the elements from index start up to but not including index stop.

9.3

Traversing a List

Traversing a list means visiting each of its elements, one after another — usually to print, examine or process them. Python offers two loop constructs for this: the for loop and the while loop.

9.4

List Methods and Built-in Functions

The list data type comes with a rich set of built-in methods and functions for everyday programming: measuring a list, building one, adding and removing elements, searching, rearranging, and summarisi…

9.5

Nested Lists

When a list appears as an element of another list, the inner list is called a nested list. Nesting lets one list carry structured sub-groups of data alongside ordinary elements.

9.6

Copying Lists

3 Q

Copying a list is one of the places where Python's behaviour surprises beginners: the "obvious" way — plain assignment — does not create a copy at all.

9.7

List as Argument to a Function

2 Q

When a list is passed as an argument to a function, what we actually pass is a reference to the list — not a fresh copy of it.

9.8

List Manipulation

3 Q

This closing section pulls the whole chapter together: creating lists, and applying the operations and methods learnt so far, inside complete working programs.

Summary

- Lists are mutable sequences in Python — the elements of a list can be changed after the list is created.

More questions

16 Q
+Show 7 questions7 questions
  1. Q1What will be the output of the following statements? i. ```python list1 = [12,32,65,26,80,10] list1.sort() print(list1) ``` ii. ```python li…Free
  2. Q2Consider the following list myList. What will be the elements of myList after the following two operations: ```python myList = [10,20,30,40]…Free
  3. Q3What will be the output of the following code segment: ```python myList = [1,2,3,4,5,6,7,8,9,10] for i in range(0,len(myList)): if i%2 == 0:…Free
  4. Q4What will be the output of the following code segment: a. ```python myList = [1,2,3,4,5,6,7,8,9,10] del myList[3:] print(myList) ``` b. ```p…Preview
  5. Q5Differentiate between append() and extend() functions of list.Preview
  6. Q6Consider a list: ```python list1 = [6,7,8,9] ``` What is the difference between the following operations on list1: a. `list1 * 2` b. `list1…Preview
  7. Q7The record of a student (Name, Roll No., Marks in five subjects and percentage of marks) is stored in the following list: ```python stRecord…Preview
+Show 9 questions9 questions
  1. Q1Write a program to find the number of times an element occurs in the list.Free
  2. Q2Write a program to read a list of n integers (positive as well as negative). Create two new lists, one having all positive numbers and the o…Free
  3. Q3Write a function that returns the largest element of the list passed as parameter.Free
  4. Q4Write a function to return the second largest number from a list of numbers.Preview
  5. Q5Write a program to read a list of n integers and find their median. Note: The median value of a list of values is the middle one when they a…Preview
  6. Q6Write a program to read a list of elements. Modify this list so that it does not contain any duplicate elements, i.e., all elements occurrin…Preview
  7. Q7Write a program to read a list of elements. Input an element from the user that has to be inserted in the list. Also input the position at w…Preview
  8. Q8Write a program to read elements of a list. a) The program should ask for the position of the element to be deleted from the list. Write a f…Preview
  9. Q9Read a list of n elements. Pass this list to a function which reverses this list in-place without creating a new list.Preview