Search Header Logo
Python Lists

Python Lists

Assessment

Presentation

Computers

11th Grade

Medium

Created by

Fabian Manning

Used 21+ times

FREE Resource

12 Slides • 7 Questions

2

Python List

Before introducing Python List, let us review

Python Variable

media

3

Python List: Variables

As in the case in math, Python uses variables to name unknown quantities

media

4

Python List: Variables

media

​Mathematics

​Python

​ y = 2

​y = 2

​y = boy

​y = 'boy'

​x = girl

​x = 'girl'

​In Python, the unknown quantities are called Data Types

Notice how the data type 'girl' and 'boy' are represented

5

Python: Variable vs List

Notice that each Variable is linked to one unknown?

That is y = 2, y = 'boy' or y = 'books'​

In Python, lists are similar but, are used to store multiple items in a single variable.

​Variable

​List

​y = 2

​y = [2, 'boy', 'book']

​y = 'boy'

​y = 'book'

Notice:

  • List conveniently assign multiple items to a variable.

  • List is identified using [ ]

  • each item is separated using commas.

6

Python: List

You can view listings as chess with drawers.

  • Each item will be placed in one drawer.

  • Each drawer will be numbered, starting from 0. (this Python is called indexing.

media

0

1

2

3

4

7

Python: List

Example: The following is an example of a list...

​y = [2, 'boy', 'book']

media

2 in slot 0

y =

boy in slot 1

book in slot 2

8

Multiple Choice

Is this the correct code for a list?

register = {"Sam", "Pheobe", Georgia", Richard"}

1

Yes

2

No

9

Multiple Choice

If you want to create an empty list called colours, which of the following pieces of code is correct?
1

colours = [ ]

2

colours = ( )

3

colours = { }

4

colors = [ ]

10

Multiple Choice

What is used to separate elements in a list?

1

Bracket

2

Comma

3

Full Stop

4

Space

11

Multiple Choice

What brackets are used to create a list?

1

()

2

[]

12

Multiple Choice

What does the '#' allow you to do?

1

Repeat code

2

Comment on code

3

Print code

4

End code

13

Multiple Choice

Which of these is the correct code for creating a list of names?

1

nameList = John, Harry, Jesse, John, Harry, Harry

2

nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")

3

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

4

nameList = [John, Harry, Jesse, John, Harry, Harry]

14

Multiple Choice

Question image

This list contains items of what data type?

1

String

2

Boolean

3

Float

4

Integer

15

More About List

List items are...

  • ordered,

  • changeable, and

  • allow duplicate values.

16

More About List

List items are ordered,

  • This 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.

17

More About List

List items are ordered,

  • This means that each item occupies a specific position (having defined order), and that the order will not change.

  • If you add new items to a list, the new items will be placed at the end of the list.

18

More About List

List items are changeable,

  • This means that the items can be change by adding, and removing items after it has been created.

19

More About List

List items allow for duplicate values.

This means that lists can have items with the same value

thislist = ["apple", "banana", "cherry", "apple", "cherry"]

This is possible since each item in the list will occupy its own position (slot).

Show answer

Auto Play

Slide 1 / 19

SLIDE