4. Lists Flashcards

1
Q

How do you create a list of the first four prime numbers?

A

primes = [2, 3, 5, 7]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Create a list of lists with products (A, B, C,…) on 3 shelves

A
products = [
[A, B, C]
[D, E, F]
G, H, I]
]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Can a list contain multiple variable types?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

For list of planets, how would you change the first one to Manchester?

A

planets[0] = ‘Manchester’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How would you change the last planet to London?

A

planets[-1] = 'London'

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you access the first 4 planets of the list?

A

planets[0:5]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Can you modify lists? What word is used to describe this?

A

Yes, they are mutable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A function attached to an object is called a ——-

A

method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you add Birmingham to the end of the list of planets

A

planets.append(‘Birmingham’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How does a tuple differ from a list?

A
  1. Uses () rather than []
  2. It is immutable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly