On National Teacher Day, meet the 2024-25 Kenan Fellows
lists_list_of_liststuples_of_python.pptx
1. Introduction to Python
Lists
Python lists are a versatile data type used to store multiple items in a
single variable. They are ordered, changeable, and allow duplicate
values.
by Shanthi Jeyabal
2. Creating a List
Definition
A Python list is created by
placing all the items
(elements) inside square
brackets [ ], separated by
commas.
Example
For example, a list of
integers: [1, 2, 3, 4, 5].
Or a list of strings: ["apple",
"banana", "cherry"].
Flexibility
Lists can contain items of
different data types, making
them extremely flexible
containers.
3. Accessing Elements in a List
1 By Index
Access elements by their index,
starting at 0 for the first item and
increasing by 1 for each subsequent
element.
2 With Negative Index
Use negative indices to access
elements from the end of the list,
starting from -1.
3 Slicing
Retrieve a specific subset of the list by slicing, using the colon operator.
4. Modifying Elements in a List
1 Updating
Directly modify the value of an element based on its index.
2 Appending
Add new elements to the end of the list using the append() method.
3 Deleting
Remove specific elements from the list using methods like remove() or the
del keyword.
5. List Methods and Functions
Common Methods
Python provides various built-in
methods, such as sort(), reverse(),
and copy().
Operational Functions
Functions like len() to get the length
of the list or max() and min() for
maximum and minimum values.
6. Slicing a List
Start and Stop
Define the start and stop indices to slice a portion of the list.
Step
Optionally specify a step to determine the increment between elements to be
included in the slice.
8. Examples of Using Lists in Python
3
Online Gaming
Storing usernames or high
scores in a list for easy
management.
15
Employee Database
Listing employee details or
performance ratings in a
structured manner.
50K
Data Analysis
Representing large datasets as
lists for efficient processing and
manipulation.