0% found this document useful (0 votes)
12 views29 pages

Python List Creation and Operations

The document outlines a lecture on List Creation and Operations in Python, covering the creation of homogeneous, heterogeneous, and nested lists, as well as methods for accessing and manipulating lists. Key features of lists, such as indexing, slicing, and various list methods (append, insert, extend, remove, pop, sort) are discussed. The lecture also highlights practical applications of lists in real-life scenarios, such as shopping carts and student record systems.

Uploaded by

revti1902
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views29 pages

Python List Creation and Operations

The document outlines a lecture on List Creation and Operations in Python, covering the creation of homogeneous, heterogeneous, and nested lists, as well as methods for accessing and manipulating lists. Key features of lists, such as indexing, slicing, and various list methods (append, insert, extend, remove, pop, sort) are discussed. The lecture also highlights practical applications of lists in real-life scenarios, such as shopping carts and student record systems.

Uploaded by

revti1902
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Academic Session 2025-26

ODD Semester Jul-Dec 2025

UNIVERSITY INSTITUTE OF ENGINEERING


DEPARTMENT OF CSE
PYTHON PROGRAMMING
(24CSP-203)
Unit No. 2 Chapter No. 2.2 Lecture No. 5

Topic : List Creation and Operations

Gitanjali Gupta – E16525 Assistant Professor


Learning Objectives
1

1. Create homogeneous, heterogeneous, and nested lists.


2. Access list elements using indexing and slicing.
3. Perform list operations using methods: append(),
insert(), extend(), remove(), pop(), sort().
4. Use lists effectively in loops and real-life data structures.

Gitanjali Gupta – E16525 Assistant Professor


Topics Covered
2

List creation, accessing, and


operations (append (), insert(),
extend(), remove(), pop(), sort(),
etc.).

Gitanjali Gupta – E16525 Assistant Professor


3

Lists in Python
What is a List?
List is one of the built-in data types in Python. A Python list is a
sequence of comma separated items, enclosed in square brackets
[ ]. The items in a Python list need not be of the same data type.
Key features:
Supports indexing
Can store mixed data types
Allows duplicate elements

Gitanjali Gupta – E16525 Assistant Professor


3

Lists in Python
Creating Lists
Homogeneous List (same type):A homogeneous list
contains elements of the same data type. This is
commonly used when all values belong to the same
category (e.g., all integers, all strings).

Gitanjali Gupta – E16525 Assistant Professor


3

Lists in Python
Creating Lists
Heterogeneous List (mixed types):A heterogeneous list
contains elements of mixed data types, such as integers,
strings, floats, and booleans. Python lists support storing
multiple data types in a single list.

Gitanjali Gupta – E16525 Assistant Professor


3

Lists in Python
Creating Lists
Nested List (list within a list):A nested list is a list
inside another list. It is used to represent multi-
dimensional data such as matrices or grouped data.

Gitanjali Gupta – E16525 Assistant Professor


3

Lists in Python
Accessing List Elements
Indexing
• Access items using their
position
• Index starts from 0
• Use negative indexing to
access from the end
Gitanjali Gupta – E16525 Assistant Professor
3

Lists in Python
List Slicing
• Python list slicing is fundamental concept that let us
easily access specific elements in a list.
• Extracts a portion of the list.

Gitanjali Gupta – E16525 Assistant Professor


3

Lists in Python
List Methods
append(): The append() method appends an element to
the end of the list.
Syntax:
[Link](elmnt)

Gitanjali Gupta – E16525 Assistant Professor


3

Lists in Python
Python List insert() method inserts an item at a specific
index in a list.
Syntax:
list_name.insert(index, element)

Gitanjali Gupta – E16525 Assistant Professor


3

Lists in Python
extend() method is used to add items from one list to the
end of another list. This method modifies the original list by
appending all items from the given iterable.
Syntax:
list_name.extend(iterable)
Parameters:
list_name: The list that will be extended
iterable: Any iterable (list, set, tuple, etc.)
Gitanjali Gupta – E16525 Assistant Professor
3

Lists in Python
remove(): Removes the first occurrence of the specified
element.

Gitanjali Gupta – E16525 Assistant Professor


3

Lists in Python
pop():
Removes and returns the element at the given index.
If no index is specified, removes the last element.

Gitanjali Gupta – E16525 Assistant Professor


3

Lists in Python
sort():
Sorts the list in-place
(modifies the original list). By
default, sorts in ascending
order.

Gitanjali Gupta – E16525 Assistant Professor


3

Lists in Python
3

Lists in Python
Copying Lists
Assignment (not an actual copy)

Proper Copy using copy():

Gitanjali Gupta – E16525 Assistant Professor


3

Lists in Python
Using Loops with Lists
For item in list:
colors = ["red", "blue", "green"]
for color in colors:
print(color)
With Index:
for i in range(len(colors)):
print(i, ":", colors[i])
Gitanjali Gupta – E16525 Assistant Professor
Applications of the Topic
23

• Shopping Cart or Billing System


• Student Record System
• Data Analysis & Preprocessing
• Menu-Driven Applications
• Working with CSV/Files

Gitanjali Gupta – E16525 Assistant Professor


Summary of the Lecture
24

1. List is a mutable, ordered collection


that can store multiple data types (e.g.,
integers, strings, floats, etc.), including
nested lists.
2. Elements can be accessed using
indexing and slicing, and lists support
looping using for or while loops.
Gitanjali Gupta – E16525 Assistant Professor
Next Lecture
7

Topic(s)

• Tuples in Python
• Working with immutable and unordered collections

Dr. Gitanjali – E16525 Assistant Professor


Quiz/ FAQ’s
27

Which of the following creates a list in Python?


A. list = (1, 2, 3)
B. list = {1, 2, 3}
C. list = [1, 2, 3]
D. list = <1, 2, 3>

Gitanjali Gupta – E16525 Assistant Professor


Quiz/ FAQ’s
26

Which method is used to add multiple elements to a


list at once?
A. append()
B. insert()
C. extend()
D. pop()

Gitanjali Gupta – E16525 Assistant Professor


Quiz/ FAQ’s
28

Which of the following removes the last element from


a list?
A. remove()
B. pop()
C. delete()
D. cut()

Gitanjali Gupta – E16525 Assistant Professor


Quiz/ FAQ’s
28

Which method sorts a list in ascending order?


A. sort()
B. arrange()
C. order()
D. sequence()

Gitanjali Gupta – E16525 Assistant Professor


References/ Articles/ Videos
29

Suggestive Readings
• Think Python How to Think Like a Computer Scientist (Allen B. Downey)
• Fundamentals of Python First Programs, 2nd Edition (Kenneth A. Lambert)
• Programming and Problem Solving with Python (Ashok Namdev Kamthane, Amit Ashok
Kamthane)

Gitanjali Gupta – E16525 Assistant Professor


Faculty-curated videos, NPTEL,
30

Coursera, LinkedIn, or other relevant


learning resources
• [Link]
• [Link]
ython
• [Link]

Gitanjali Gupta – E16525 Assistant Professor


Class-Wise Feedback
29

Dr. Gitanjali – E16525 Assistant Professor


32

Thank You

You might also like