
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
Scientific Method review
Presentation
•
9th Grade
20 questions
Proofs In Geometry
Presentation
•
9th Grade
22 questions
Year 9-UserInput
Presentation
•
9th Grade
21 questions
5.Portable storage
Presentation
•
9th Grade
24 questions
1.5 Gusta o Gustan?
Presentation
•
9th Grade
22 questions
Factors That Affect Network Performance
Presentation
•
9th Grade
20 questions
File Sizes
Presentation
•
9th Grade
21 questions
Quadratic Formula
Presentation
•
9th Grade
Popular Resources on Wayground
21 questions
Continents and Oceans
Quiz
•
6th Grade
20 questions
Parts of Speech
Quiz
•
5th Grade
16 questions
Subject & Predicate
Quiz
•
5th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
12 questions
Map Skills
Quiz
•
3rd Grade
22 questions
Continents and Oceans
Quiz
•
5th Grade
15 questions
Rounding Decimals
Quiz
•
5th Grade
20 questions
Brand Labels
Quiz
•
5th - 12th Grade
Discover more resources for Computers
16 questions
Module 1 Topic 2 Vocabulary Test
Quiz
•
9th - 12th Grade
17 questions
Chapter 1 Review
Quiz
•
9th Grade
20 questions
Google Slides Quiz
Quiz
•
9th Grade
30 questions
Python- if -ifelse-elif
Quiz
•
9th - 12th Grade
10 questions
Exploring Digital Citizenship Essentials
Interactive video
•
6th - 10th Grade
46 questions
Level 1 Google Sheets Midterm Flashcard
Flashcard
•
9th - 12th Grade
40 questions
Introduction to Microsoft Word
Quiz
•
8th - 12th Grade
10 questions
Exploring Cybersecurity Techniques and Threats
Interactive video
•
6th - 10th Grade