
Listing in python
Presentation
•
Computers
•
9th Grade
•
Medium
Boazi Tarmo
Used 1+ times
FREE Resource
10 Slides • 18 Questions
1
LESSON 2: PYTHON LIST
How do we use list in python??
2
List
Lists are used to store multiple items in a single variable.
Lists are created using square brackets
thislist = ["apple", "banana", "cherry"]
print(thislist)
note:
List items are indexed, the first item has index [0], the second item has index [1] etc.
3
List Items
List items are ordered, changeable, and allow duplicate values.
1.Ordered
When we say that lists are ordered, it means that the items have a defined order, and that order will not change.
If you add new items to a list, the new items will be placed at the end of the list.
4
2.Changeable
The list is changeable, meaning that we can change, add, and remove items in a list after it has been created.
5
3.Allow Duplicates
Since lists are indexed, lists can have items with the same value:
Example
Lists allow duplicate values:
thislist = ["apple", "banana", "cherry", "apple", "cherry"]
print(thislist)
6
List Length
To determine how many items a list has, use the len() function:
Example
Print the number of items in the list:
thislist = ["apple", "banana", "cherry"]
print(len(thislist))
7
List Items - Data Types
List items can be of any data type:
Example
String, int and boolean data types:
list1 = ["apple", "banana", "cherry"]
list2 = [1, 5, 7, 9, 3]
list3 = [True, False, False]
print(list1)
print(list2)
print(list3)
8
A list can contain different data types:
Example
A list with strings, integers and boolean values:
list1 = ["abc", 34, True, 40, "male"]
print(list1)
9
type()
From Python's perspective, lists are defined as objects with the data type 'list':
<class 'list'>
Example
What is the data type of a list?
mylist = ["apple", "banana", "cherry"]
print(type(mylist))
10
The list() Constructor
It is also possible to use the list() constructor when creating a new list.
Example
Using the list() constructor to make a List:
thislist = list(("apple", "banana", "cherry")) # note the double round-brackets
print(thislist)
11
Multiple Choice
Lists are used to store single item in a single variable.
True
False
12
Multiple Choice
List items are ordered, changeable, and allow duplicate values.
True
False
13
Multiple Choice
List items are indexed, the first item has index [1], the second item has index [2] etc.
True
False
14
Multiple Choice
When we say that lists are ordered, it means that the items have a defined order, and that order will not change.
True
False
15
Multiple Choice
List items can be of any data type:
True
False
16
Multiple Choice
If you add new items to a list, the new items will be placed at the end of the list.
True
False
17
Multiple Choice
Which of these is the correct code for creating a list of names?
nameList = John, Harry, Jesse, John, Harry, Harry
nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList = [John, Harry, Jesse, John, Harry, Harry]
18
Multiple Choice
List items have an index number. In the following list, which item has the index number of 3?
["John", "Harry", "Jesse", "John", "Harry", "Harry"]
"John"
"Harry"
"Jesse"
19
Multiple Choice
Which of these pieces of code would return the name "Harry" from the following list?
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList()
nameList[1]
NameList(4)
nameList["4"]
20
Multiple Choice
The list needs one more name added to the end - "Felipe". Which piece of code below would do this?
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList.append(Felipe)
append(nameList,"Felipe")
nameList.append["Felipe",7]
nameList.append("Felipe")
21
Multiple Choice
What will be the result of the following syntax:
mylist = ['apple', 'banana', 'cherry']
print(mylist[1])
22
Multiple Choice
23
Multiple Choice
What will be the result of the following syntax:
mylist = ['apple', 'banana', 'banana', 'cherry']
print(mylist[2])
24
Multiple Choice
Is this the correct code for a list?
register = {"Sam", "Pheobe", Georgia", Richard"}
Yes
No
25
Multiple Choice
True or False.
List items cannot be removed after the list has been created.
26
Multiple Choice
The count() method returns the number of times the specified element appears in the list.
What is the output of this code?
3
2
1
0
27
Multiple Choice
Output of this code?
[2,4,6,8,10]
['2','4','6','8','10']
[0,2,4,6,8]
[10,8,6,4,2]
28
Multiple Choice
What is the index of “grape” in the list
[“apple”, “grape”, “orange”, “watermelon”]?
0
1
2
3
LESSON 2: PYTHON LIST
How do we use list in python??
Show answer
Auto Play
Slide 1 / 28
SLIDE
Similar Resources on Wayground
22 questions
Understanding Taxes
Presentation
•
8th Grade
21 questions
Meet Scratch
Presentation
•
8th Grade
21 questions
Monohybrid Crosses (Punnet Squares)
Presentation
•
9th - 10th Grade
20 questions
S3 Web Revison
Presentation
•
9th Grade
22 questions
Parts of Speech Test Review 2
Presentation
•
9th - 10th Grade
22 questions
Ch. 15-2 GN: Consumer Rights and Responsibilities
Presentation
•
9th Grade
22 questions
LINK
Presentation
•
10th Grade
23 questions
The Computer
Presentation
•
10th Grade
Popular Resources on Wayground
19 questions
Naming Polygons
Quiz
•
3rd Grade
10 questions
Prime Factorization
Quiz
•
6th Grade
20 questions
Math Review
Quiz
•
3rd Grade
15 questions
Fast food
Quiz
•
7th Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
20 questions
Inferences
Quiz
•
4th Grade
19 questions
Classifying Quadrilaterals
Quiz
•
3rd Grade