Cette leçon contient 22 diapositives, avec quiz interactifs et diapositives de texte.
Éléments de cette leçon
Lists in Python
Cited from W3Schools.com
Said Ahghari
Slide 1 - Diapositive
Data Types
Python supports various data types such as integers, floats, strings, boolean, and lists.
Slide 2 - Diapositive
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 - Diapositive
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 - Diapositive
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 - Diapositive
Coding Activity: creating and outputting a list
In Python, create a list of 5 students. Output the list.
myStudents = ["Said", "John", "Iman", "Nour", "Jane"] print (myStudents [1:4] ) Which items are displayed? What is the output type?
Slide 14 - Carte mentale
Answers:
['John', 'Iman', 'Nour']
It is a list because of the square brackets ([ ])
Slide 15 - Diapositive
Slide 16 - Diapositive
How many items will be outputted using the following code? fruitList = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] print(fruitList[ :4])
A
Three items
B
Four items
C
None
D
Five items
Slide 17 - Quiz
Explain the following line of code. print(fruitList[:4])
Slide 18 - Question ouverte
What will be the result of the following syntax: mylist = ['apple', 'banana', 'cherry'] print(mylist[-1])
A
Apple
B
Banana
C
Cherry
D
Error message
Slide 19 - Quiz
What will be the result of the following syntax: mylist = ['apple', 'banana', 'cherry', 'kiwi', 'melon', 'mango'] print(mylist[-2:])
A
['kiwi', 'melon', 'mango']
B
['melon', 'mango']
C
error message
D
['apple', 'banana']
Slide 20 - Quiz
What is the output of the code below: my_list = [1, 2, 3, 4, 5] print(my_list[::-1])
Slide 21 - Carte mentale
What is the output of the code below: my_list = [1, 2, 3, 4, 5] print(my_list[::-1])