Lists in Python

Lists in Python
By Said Ahghari
1 / 10
next
Slide 1: Slide
ComputingLower Secondary (Key Stage 3)

This lesson contains 10 slides, with text slides.

Items in this lesson

Lists in Python
By Said Ahghari

Slide 1 - Slide

Data Types
Python supports various data types such as integers, floats, strings, boolean, and lists.

Slide 2 - Slide

Data Types for Variables
In Python, variables can hold different types of data, such as numbers, strings, boolean, and lists. Each data type has its own characteristics and usage.

Slide 3 - Slide

Lists
In python one of the most used data structures is a list.
Lists are used to store similar data, one item after another.
For example:
  • items you need to buy from a shopping list
  • names of students in a class

A list is an example of a 1 Dimensional array.

Slide 4 - Slide

List Data Type
Lists are a collection of items that can be manipulated and accessed individually. The list data type in Python is used to store multiple values in a single variable. It is denoted by square brackets ([]).
marks = [25, 65, 95, 33]    #a list of 4 numbers  
names = []                              #an empty list

Slide 5 - Slide

Coding Activity: creating and outputting a list
In Python, create a list of 5 students.  Output the list. 
timer
5:00

Slide 6 - Slide

Solution
myStudents = ["Said", "John", "Iman", "Nour", "Jane"]
print(myStudents)

Slide 7 - Slide

Finding the number of items in a list
To find the number of items in a list use the len() function.
myStudents = ["Said", "John", "Iman", "Nour", "Jane"]
print(len(myStudents))
Output:
5

Slide 8 - Slide

List items' position
Each list item is held in a position in the list.
The list position starts from zero (0).

0
1
2
3
4
Said
John
Iman
Nour
Jane
Position (index)
List item

Slide 9 - Slide

Slide 8: Recap and Summary
In this lesson, we learned about various data types in Python, including numeric, string, boolean, list, tuple, and dictionary data types.

Slide 10 - Slide